mirror of
https://github.com/affaan-m/ECC.git
synced 2026-10-15 12:45:29 +02:00
test(gateguard): use descriptive helper and fixture names
This commit is contained in:
+1056
-1068
File diff suppressed because it is too large
Load Diff
@@ -434,9 +434,7 @@ test('isSensitiveTarget matches every listed basename, segment and prefix rule',
|
||||
'src/secrets/vault.py', 'src/payment/charge.py', 'src/payments/x.py', 'app/billing/invoice.rb',
|
||||
'db/migrations/0001_init.sql', 'auth/readme.md', 'src/auth',
|
||||
'.github/workflows/ci.yml', '.github/workflows/sub/x.yaml', './.github/workflows/ci.yml',
|
||||
// Below an ancestor (a fake worktree prefix, or an absolute path outside the root).
|
||||
'.claude/worktrees/fake/.github/workflows/ci.yml', '/elsewhere/repo/.github/workflows/ci.yml',
|
||||
// Case-insensitive, and Windows-style separators.
|
||||
'SRC/Auth/Login.py', '.ENV', 'Certs/Server.PEM', 'src\\billing\\x.py'
|
||||
];
|
||||
for (const p of sensitive) assert.strictEqual(isSensitiveTarget(p), true, p);
|
||||
@@ -471,12 +469,10 @@ test('isSensitiveTargetFor uses the project-relative class path', () => {
|
||||
assert.strictEqual(isSensitiveTargetFor(`${proj}/src/auth/app.py`, data), true);
|
||||
assert.strictEqual(isSensitiveTargetFor('src/billing/x.py', data), true, 'relative to cwd');
|
||||
assert.strictEqual(isSensitiveTargetFor(`${proj}/.github/workflows/ci.yml`, data), true);
|
||||
// A real worktree mirrors the project: its prefix is stripped before the rules apply.
|
||||
fs.mkdirSync(path.join(proj, '.claude', 'worktrees', 'w1'), { recursive: true });
|
||||
fs.writeFileSync(path.join(proj, '.claude', 'worktrees', 'w1', '.git'), 'gitdir: x\n');
|
||||
assert.strictEqual(isSensitiveTargetFor(`${proj}/.claude/worktrees/w1/.github/workflows/ci.yml`, data), true);
|
||||
assert.strictEqual(isSensitiveTargetFor(`${proj}/.claude/worktrees/w1/src/app.py`, data), false);
|
||||
// Windows spellings that name the same file are normalized first.
|
||||
assert.strictEqual(isSensitiveTargetFor(`${proj}/.env.`, data), true);
|
||||
});
|
||||
} finally {
|
||||
@@ -486,7 +482,7 @@ test('isSensitiveTargetFor uses the project-relative class path', () => {
|
||||
|
||||
test('isSensitiveTargetFor also judges the real (symlink-resolved) path', () => {
|
||||
const root = tempProject();
|
||||
const outside = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'gateguard-r1-outside-')));
|
||||
const outside = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'gateguard-outside-')));
|
||||
try {
|
||||
withProjectDir(root, () => {
|
||||
const data = { cwd: root };
|
||||
|
||||
@@ -92,7 +92,6 @@ const filler = prefix => {
|
||||
// ── turn id ──
|
||||
console.log('turn id:');
|
||||
|
||||
// Every user record of a turn (prompt and tool_results) carries the same promptId.
|
||||
test('boundary in window with promptId -> turnId is the promptId', () => {
|
||||
const t = writeTranscript([
|
||||
human('old', { promptId: 'prompt-old' }),
|
||||
@@ -208,7 +207,6 @@ test('no transcript, a directory, or a whole file without a boundary -> no searc
|
||||
assert.strictEqual(noBoundary.turnId, null);
|
||||
});
|
||||
|
||||
// The turn id is the boundary's own promptId; a clipped window needs agreeing promptIds.
|
||||
test('boundary in window -> the boundary record\'s own promptId, not a newer record\'s', () => {
|
||||
const late = { ...toolResult('toolu_n3a'), promptId: 'P1' };
|
||||
const t = writeTranscript([human('one', { promptId: 'P1' }), human('two', { promptId: 'P2' }), toolUse('toolu_n3a', 'Bash', { command: 'true' }), late]);
|
||||
@@ -248,7 +246,6 @@ test('clipped window without a boundary -> promptId only when all user records a
|
||||
assert.strictEqual(scanCurrentTurn(partial).turnId, 'PA', 'records without a promptId do not disagree');
|
||||
});
|
||||
|
||||
// Malformed records and inputs never throw; the record is skipped.
|
||||
const MALFORMED_RECORDS = [
|
||||
'{"type":"assistant"}',
|
||||
'{"type":"assistant","message":null}',
|
||||
@@ -315,7 +312,6 @@ test('scanCurrentTurn skips each malformed record and keeps the rest of the turn
|
||||
assert.strictEqual(scan.turnId, 'PM', `${bad}: turn id`);
|
||||
assert.deepStrictEqual(scan.searches.map(s => s.name), ['Grep'], `${bad}: search kept`);
|
||||
}
|
||||
// A user record without usable content is a turn boundary, which can only shrink the window.
|
||||
for (const bad of ['{"type":"user"}', '{"type":"user","message":null}', '{"type":"user","message":{"content":{}}}']) {
|
||||
const t = writeTranscript([human('go', { promptId: 'PM' }), ...search('toolu_m2', 'Grep', { pattern: 'payment' }), bad]);
|
||||
const scan = scanCurrentTurn(t, `toolu_pending_${seq}`);
|
||||
|
||||
Reference in New Issue
Block a user