Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

chore(w4): keep secret-scan.ts under its 1,500-line cap and type the reindex handler test context

time-attacka3f8a56a0c98
diff --git a/src/core/secret-scan-labeled.ts b/src/core/secret-scan-labeled.ts
index 2586bb81b0..80cb6c9c4c 100644
--- a/src/core/secret-scan-labeled.ts
+++ b/src/core/secret-scan-labeled.ts
@@ -275,7 +275,7 @@ export function newTableScanState(): TableScanState {
* line (a header row is the one above a separator). Linear in the line.
*/
export function tableCredentialCells(line: string, next: string | undefined, state: TableScanState): Array<{ start: number; value: string }> {
- const cells = tableCells(line);
+ const cells = line.includes('|') ? tableCells(line) : null;
const out: Array<{ start: number; value: string }> = [];
if (!cells) {
state.columns = null;
diff --git a/src/core/secret-scan.ts b/src/core/secret-scan.ts
index 9ed03e257c..519cf8655f 100644
--- a/src/core/secret-scan.ts
+++ b/src/core/secret-scan.ts
@@ -38,8 +38,7 @@ import {
danglingLabel,
labeledEchoEligible,
labeledValueIsCredential,
- newTableScanState,
- tableCredentialCells,
+ newTableScanState, tableCredentialCells,
} from './secret-scan-labeled.ts';
// ── Types ───────────────────────────────────────────────────────────────────
@@ -982,8 +981,7 @@ function scanInternal(text: string, opts: ScanOpts): RawHit[] {
const lineStart = offset;
offset += line.length + 1;
const dangling = opts.labeledCredentials === true && i > 0 ? danglingLabel(lines[i - 1] ?? '') : null;
- const cells = table && line.includes('|') ? tableCredentialCells(line, lines[i + 1], table) : [];
- if (table && !line.includes('|')) { table.columns = null; table.previous = null; }
+ const cells = table ? tableCredentialCells(line, lines[i + 1], table) : [];
if (line.length < 8 && !dangling && cells.length === 0) continue;
// ENG-12: a line wholly inside a private-key claim is already redacted by
// it; hits on it would only double-report (one key, one finding).
@@ -1040,11 +1038,7 @@ function scanInternal(text: string, opts: ScanOpts): RawHit[] {
claim(p.name, value, start);
}
}
- for (const cell of cells) {
- if (taken && anyTaken(taken, cell.start, cell.start + cell.value.length)) continue;
- taken ??= new Uint8Array(line.length);
- claim('labeled_credential', cell.value, cell.start);
- }
+ for (const c of cells) if (!taken || !anyTaken(taken, c.start, c.start + c.value.length)) { taken ??= new Uint8Array(line.length); claim('labeled_credential', c.value, c.start); }
}
return hits;
}
diff --git a/test/reindex-consent.test.ts b/test/reindex-consent.test.ts
index e0b6c1e893..4d7ec9461d 100644
--- a/test/reindex-consent.test.ts
+++ b/test/reindex-consent.test.ts
@@ -119,7 +119,7 @@ describe('W4.5: the reindex job handler', () => {
const ctx = (spend?: boolean): MinionJobContext => ({
id: 41, name: 'reindex', data: { markdown: true }, attempts_made: 0, signal: new AbortController().signal,
...(spend ? { spend: { record: jobSpendAuthorization({ consented_effects: ['paid'], cap_usd: 5, cap_source: 'user', via: 'yes' }, { command: 'jobs submit reindex', of: 1 }), budget_key: 'group:x' } } : {}),
- }) as MinionJobContext;
+ }) as unknown as MinionJobContext;
test('a queued job without a stored authorization fails with confirmation_required and spends nothing', async () => {
let thrown: unknown;