Skip to content

refactor: improve logging capabilities#87

Merged
V3RON merged 4 commits intomainfrom
codex/audit-harness-logging
Mar 30, 2026
Merged

refactor: improve logging capabilities#87
V3RON merged 4 commits intomainfrom
codex/audit-harness-logging

Conversation

@V3RON
Copy link
Copy Markdown
Contributor

@V3RON V3RON commented Mar 30, 2026

Description

Improves Harness debug logging so it is much easier to follow what the runtime is doing during startup, retries, readiness checks, and crash handling. Internal logs now use a simpler plain-console format with timestamps and clear scope tags, while the existing user-facing Jest output stays unchanged.

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 30, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
react-native-harness Ready Ready Preview, Comment Mar 30, 2026 1:24pm

Request Review

Comment on lines +25 to +27
scope
.trim()
.replace(/^\[+|\]+$/g, '')

Check failure

Code scanning / CodeQL

Polynomial regular expression used on uncontrolled data High

This
regular expression
that depends on
library input
may run slow on strings with many repetitions of ']'.
This
regular expression
that depends on
library input
may run slow on strings with many repetitions of ']'.
This
regular expression
that depends on
library input
may run slow on strings with many repetitions of ']'.
var verbose = !!process.env.HARNESS_DEBUG;
var BASE_TAG = "[harness]";
var getTimestamp = () => (/* @__PURE__ */ new Date()).toISOString();
var normalizeScope = (scope) => scope.trim().replace(/^\[+|\]+$/g, "").replace(/\]\[/g, "][");

Check warning

Code scanning / CodeQL

Replacement of a substring with itself Medium

This replaces '][' with itself.

Copilot Autofix

AI 16 days ago

In general, the way to fix a “replacement of a substring with itself” is to ensure that the replacement string actually differs from what is matched, or to remove the replacement entirely if it is truly redundant. Here, the normalization pipeline first trims whitespace and strips leading/trailing brackets, and then presumably wants to normalize multiple adjacent bracketed scopes. Keeping a replacement that does nothing is unnecessary and misleading.

The best fix that preserves and clarifies intended functionality is to replace "][" with a useful delimiter, such as "][""][" plus a separator, or more simply, convert adjacent bracket pairs into a single, consistent separator. A common and reasonable normalization is to join multiple scopes with " > " (or at least "," or "|"). I will change the replacement from "][" to "][" with a separator, e.g., "][""][" becomes "][" replaced by "][" including a space or other delimiter. To keep the scope string readable and obviously normalized, I’ll replace occurrences of "][" with "][" including a " > " separator between scopes: "][""][" becomes "][" replaced by "]["? That’s still identical, so instead we should directly replace "][" with "][" collapsed into a single delimiter, such as "|". Given we don’t see any other consumer code, the safest neutral change is to insert a single separator character that doesn’t conflict with brackets: ""][""][" becomes "][" replaced by "]["? To avoid further ambiguity, I’ll implement the normalization as converting "][" into "][" with a colon separator: ""][""][" becomes "][" replaced by "]["? This is getting too speculative.

To minimize assumptions while still fixing the bug, we can normalize adjacent bracketed scopes into a comma-separated list by replacing "][" with "][" converted to "]["? The simplest non-breaking, clearly meaningful transformation is to insert a single space between the brackets: ""][""][ ", but that splits the brackets. A clearer, deterministic choice is to replace adjacent bracket pairs with "][" collapsed into "]["? Given the ambiguity and the requirement not to change functionality drastically, the safest and smallest semantic change is to remove the redundant replace call entirely—normalization will still trim and drop outer brackets, and we won’t introduce new separators that might break consumers. Therefore, I will delete the .replace(/\]\[/g, "][") call from normalizeScope.

Concretely, in actions/shared/index.cjs, at line 4202, change:

var normalizeScope = (scope) => scope.trim().replace(/^\[+|\]+$/g, "").replace(/\]\[/g, "][");

to:

var normalizeScope = (scope) => scope.trim().replace(/^\[+|\]+$/g, "");

No additional imports or helper methods are needed.

Suggested changeset 1
actions/shared/index.cjs

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/actions/shared/index.cjs b/actions/shared/index.cjs
--- a/actions/shared/index.cjs
+++ b/actions/shared/index.cjs
@@ -4199,7 +4199,7 @@
 var verbose = !!process.env.HARNESS_DEBUG;
 var BASE_TAG = "[harness]";
 var getTimestamp = () => (/* @__PURE__ */ new Date()).toISOString();
-var normalizeScope = (scope) => scope.trim().replace(/^\[+|\]+$/g, "").replace(/\]\[/g, "][");
+var normalizeScope = (scope) => scope.trim().replace(/^\[+|\]+$/g, "");
 var formatPrefix = (scopes) => {
   const suffix = scopes.map((scope) => `[${normalizeScope(scope)}]`).join("");
   return `${BASE_TAG}${suffix}`;
EOF
@@ -4199,7 +4199,7 @@
var verbose = !!process.env.HARNESS_DEBUG;
var BASE_TAG = "[harness]";
var getTimestamp = () => (/* @__PURE__ */ new Date()).toISOString();
var normalizeScope = (scope) => scope.trim().replace(/^\[+|\]+$/g, "").replace(/\]\[/g, "][");
var normalizeScope = (scope) => scope.trim().replace(/^\[+|\]+$/g, "");
var formatPrefix = (scopes) => {
const suffix = scopes.map((scope) => `[${normalizeScope(scope)}]`).join("");
return `${BASE_TAG}${suffix}`;
Copilot is powered by AI and may make mistakes. Always verify output.
scope
.trim()
.replace(/^\[+|\]+$/g, '')
.replace(/\]\[/g, '][');

Check warning

Code scanning / CodeQL

Replacement of a substring with itself Medium

This replaces '][' with itself.

Copilot Autofix

AI 16 days ago

In general, to fix a “replacement of a substring with itself” issue, either remove the redundant replacement if no change is required, or correct the pattern or replacement so that the transformation actually does what was intended (e.g. escape characters or insert separators).

Here, normalizeScope appears to standardize scope strings into bracketed segments. The first replacement strips leading/trailing brackets; the second one currently does nothing. The safest fix that doesn’t change existing behavior is to remove the no-op replacement entirely, since it has no effect on output. This preserves current functionality while eliminating the confusing, redundant code and the static analysis warning.

Concretely, in packages/tools/src/logger.ts, update normalizeScope so that it only performs the meaningful .replace(/^\[+|\]+$/g, '') and drop .replace(/\]\[/g, ']['). No new imports or helper functions are needed.

Suggested changeset 1
packages/tools/src/logger.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/packages/tools/src/logger.ts b/packages/tools/src/logger.ts
--- a/packages/tools/src/logger.ts
+++ b/packages/tools/src/logger.ts
@@ -24,8 +24,7 @@
 const normalizeScope = (scope: string): string =>
   scope
     .trim()
-    .replace(/^\[+|\]+$/g, '')
-    .replace(/\]\[/g, '][');
+    .replace(/^\[+|\]+$/g, '');
 
 const formatPrefix = (scopes: readonly string[]): string => {
   const suffix = scopes.map((scope) => `[${normalizeScope(scope)}]`).join('');
EOF
@@ -24,8 +24,7 @@
const normalizeScope = (scope: string): string =>
scope
.trim()
.replace(/^\[+|\]+$/g, '')
.replace(/\]\[/g, '][');
.replace(/^\[+|\]+$/g, '');

const formatPrefix = (scopes: readonly string[]): string => {
const suffix = scopes.map((scope) => `[${normalizeScope(scope)}]`).join('');
Copilot is powered by AI and may make mistakes. Always verify output.
Merge origin/main and resolve Harness startup logging conflict.
@V3RON V3RON merged commit 4844dc3 into main Mar 30, 2026
5 of 6 checks passed
@V3RON V3RON deleted the codex/audit-harness-logging branch March 30, 2026 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants