Skip to content
Merged
Show file tree
Hide file tree
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
84 changes: 84 additions & 0 deletions src/genie-commands/__tests__/update.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import {
type VerifyResult,
_resetNextDeprecationLatchForTest,
applyConvergenceExitSignal,
attemptAlreadyCurrentDeliveryRepair,
compareVersions,
createPrivateUpdateTempRoot,
decideDowngrade,
Expand All @@ -60,6 +61,7 @@ import {
hashPhysicalFileIncrementally,
isGenieProcessSnapshotLine,
manifestUrlForChannel,
mapAlreadyCurrentRepairOutcome,
narrowUpdateAgentSyncSelection,
normalizeVersion,
persistChannel,
Expand Down Expand Up @@ -2766,3 +2768,85 @@ describe('applyConvergenceExitSignal — exit 2 only on delivery-pending (D3 gua
expect(logs.join('\n')).not.toContain('deliveryComplete');
});
});

describe('mapAlreadyCurrentRepairOutcome — pure repair→directive mapping (Group D deliverable 1)', () => {
test('an old-parent publish (activation-pending) hands off to setup', () => {
expect(
mapAlreadyCurrentRepairOutcome({
kind: 'published',
record: {
schemaVersion: 1,
deliveryId: 'a'.repeat(32),
targetVersion: '5.260722.11',
canonicalPayloadSha256: 'a'.repeat(64),
channel: 'dev',
deliveredAt: '2026-07-22T00:00:00.000Z',
},
handoff: 'activation-pending',
artifactSha256: 'd'.repeat(64),
}),
).toEqual({ action: 'exit-handoff' });
});

test('a target-current publish reports the repair and continues the current path', () => {
expect(
mapAlreadyCurrentRepairOutcome({
kind: 'published',
record: {
schemaVersion: 1,
deliveryId: 'a'.repeat(32),
targetVersion: '5.260722.11',
canonicalPayloadSha256: 'a'.repeat(64),
channel: 'dev',
deliveredAt: '2026-07-22T00:00:00.000Z',
},
handoff: 'current',
artifactSha256: 'd'.repeat(64),
}),
).toEqual({ action: 'repaired-current' });
});

test('already-matching, channel-advanced, and failed all proceed unchanged', () => {
expect(mapAlreadyCurrentRepairOutcome({ kind: 'already-matching' })).toEqual({ action: 'proceed-current' });
expect(
mapAlreadyCurrentRepairOutcome({ kind: 'channel-advanced', from: '5.260722.11', to: '5.260722.12' }),
).toEqual({ action: 'proceed-current' });
expect(
mapAlreadyCurrentRepairOutcome({
kind: 'failed',
stage: 'download-verify',
detail: 'x',
deliveryComplete: false,
}),
).toEqual({ action: 'proceed-current' });
});
});

describe('attemptAlreadyCurrentDeliveryRepair — fail-closed skip with no install (CI-portable, no network/codex)', () => {
let prevGenieHome: string | undefined;
let dir: string;

beforeEach(() => {
prevGenieHome = process.env.GENIE_HOME;
dir = mkdtempSync(join(tmpdir(), 'update-repair-skip-'));
process.env.GENIE_HOME = dir;
});

afterEach(() => {
if (prevGenieHome === undefined) Reflect.deleteProperty(process.env, 'GENIE_HOME');
else process.env.GENIE_HOME = prevGenieHome;
rmSync(dir, { recursive: true, force: true });
});

test('an empty GENIE_HOME (no installed payload) proceeds without any lease, download, or mutation', async () => {
// No plugins/genie payload and no binary ⇒ observeInstalledForRepair returns
// null ⇒ the repair is skipped entirely. This is the common already-current
// case in a CI environment: never touches the network or the codex CLI.
const directive = await attemptAlreadyCurrentDeliveryRepair('dev', 'linux-x64');
expect(directive).toEqual({ action: 'proceed-current' });
// No lease file was created (the skip returns before lease acquisition).
expect(existsSync(join(dir, '.codex-lifecycle.lock'))).toBe(false);
// No delivery record was minted.
expect(existsSync(join(dir, '.codex-plugin-delivery-record.json'))).toBe(false);
});
});
Loading
Loading