Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 22 additions & 17 deletions packages/cli/src/commands/review/lib/run-ledger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -686,23 +686,28 @@ describe('the properties the threat model rests on', () => {
expect(priorSessionIds(plan, envOf('S2'))).toEqual([]);
});

it('refuses to append over a ledger it could not read', () => {
// A present-but-unreadable REGULAR file holds every recorded entry, and
// this append rewrites the whole file from what it read — proceeding on
// a transient fault would clobber attempt 1's address exactly when a
// resume needs it.
appendRunSession(plan, envOf('S1'));
const before = readFileSync(runSessionsPath(plan), 'utf8');
chmodSync(runSessionsPath(plan), 0o000);
try {
appendRunSession(plan, envOf('S2'));
} finally {
chmodSync(runSessionsPath(plan), 0o644);
}
expect(readFileSync(runSessionsPath(plan), 'utf8')).toBe(before);
authorize('S3');
expect(priorSessionIds(plan, envOf('S3'))).toEqual(['S1']);
});
it.skipIf(process.platform === 'win32' || process.getuid?.() === 0)(
'refuses to append over a ledger it could not read',
() => {
// A present-but-unreadable REGULAR file holds every recorded entry, and
// this append rewrites the whole file from what it read — proceeding on
// a transient fault would clobber attempt 1's address exactly when a
// resume needs it. chmod 0o000 is a POSIX-only fault: on Windows it
// toggles the read-only attribute and the file stays readable, and root
// bypasses the mode entirely — the repo convention for this shape.
appendRunSession(plan, envOf('S1'));
const before = readFileSync(runSessionsPath(plan), 'utf8');
chmodSync(runSessionsPath(plan), 0o000);
try {
appendRunSession(plan, envOf('S2'));
} finally {
chmodSync(runSessionsPath(plan), 0o644);
}
expect(readFileSync(runSessionsPath(plan), 'utf8')).toBe(before);
authorize('S3');
expect(priorSessionIds(plan, envOf('S3'))).toEqual(['S1']);
},
);

it('does not write at all when the id fails the charset gate', () => {
// The write-side guard, discriminated from the read-side one by looking
Expand Down
Loading