Skip to content

Commit a00162a

Browse files
committed
fix(#2682): name the raw-value table's obligation and keep the runner log on CI
Two CI findings: - `IOS_TARGET_ACTIVATION_PRIOR_STATES` had no consumer once the decode table stopped indexing it, so the production-exports audit failed. The list is the vocabulary the table must cover, so it now has the assertion it was always supposed to have: every declared state has to be reachable from some raw value, or a future enum case would be disclosed as `unknown` forever and nobody would notice. - The activation lane failed on the CI simulator with no disclosure, and the job uploads artifacts rather than the state dir, so nothing showed whether the runner declined to activate, activated without stamping, or stamped something the decoder refused. The lane now copies the session's `runner.log` into its artifact directory when it fails.
1 parent 2dc9c83 commit a00162a

2 files changed

Lines changed: 43 additions & 0 deletions

File tree

‎packages/platform-apple/src/runner/__tests__/target-activation.test.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import fs from 'node:fs';
33
import path from 'node:path';
44
import { fileURLToPath } from 'node:url';
55
import { test } from 'vitest';
6+
import { IOS_TARGET_ACTIVATION_PRIOR_STATES } from '@agent-device/contracts/ios-target-activation';
67
import {
78
TARGET_ACTIVATION_WIRE_KEY,
89
readTargetActivationFact,
@@ -15,6 +16,24 @@ const swiftModelsPath = path.resolve(
1516
'../../../../../apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Models.swift',
1617
);
1718

19+
/**
20+
* The decode table is declared by raw value rather than by position, which buys safety against a
21+
* reordered enum at the price of a new obligation: a state the contract declares but no raw value
22+
* names would be disclosed as `unknown` forever, silently. This is the assertion that keeps the two
23+
* declarations in step.
24+
*/
25+
test('every declared prior state is reachable from some raw value', () => {
26+
const named = new Set<string>();
27+
for (let raw = 0; raw < 16; raw++) {
28+
const fact = readTargetActivationFact(wire('stale_target', raw));
29+
if (fact) named.add(fact.priorState);
30+
}
31+
assert.deepEqual(
32+
IOS_TARGET_ACTIVATION_PRIOR_STATES.filter((state) => !named.has(state)),
33+
[],
34+
);
35+
});
36+
1837
test('target activation fact decodes every reason the runner can stamp', () => {
1938
assert.deepEqual(readTargetActivationFact(wire('stale_target', 2)), {
2039
reason: 'stale_target',

‎test/integration/smoke-ios-target-activation.test.ts‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,36 @@ test(
105105
false,
106106
'second capture re-disclosed a repair it did not perform',
107107
);
108+
} catch (error) {
109+
throw await withRunnerLogEvidence(context, error);
108110
} finally {
109111
await cleanupSession(context);
110112
}
111113
},
112114
);
113115

116+
/**
117+
* The runner writes what it decided — `AGENT_DEVICE_RUNNER_ACTIVATE`, `_SKIPPED`, and the stamped
118+
* fact — only to the session's `runner.log`, and the CI job uploads artifacts and not the state dir.
119+
* A lane that fails without that file leaves the reader guessing whether the runner declined to
120+
* activate, activated without stamping, or stamped something the decoder refused.
121+
*/
122+
async function withRunnerLogEvidence(context: LiveContext, error: unknown): Promise<Error> {
123+
const source = path.join(context.stateDir, 'sessions', context.session, 'runner.log');
124+
const destination = path.join(context.artifactDir, 'target-activation-runner.log');
125+
let note = `runner log not found at ${source}`;
126+
try {
127+
await fs.copyFile(source, destination);
128+
note = `runner log copied to ${destination}`;
129+
} catch {
130+
// The artifact is the point; a missing log is reported and the original failure still stands.
131+
}
132+
const message = error instanceof Error ? error.message : String(error);
133+
const enriched = new Error(`${message}\n${note}`);
134+
enriched.stack = error instanceof Error ? error.stack : enriched.stack;
135+
return enriched;
136+
}
137+
114138
/** Poll `snapshot -i` until the runner reports the repair, or fail with the last response. */
115139
async function captureUntilDisclosed(context: LiveContext) {
116140
const deadline = Date.now() + HANDOFF_DEADLINE_MS;

0 commit comments

Comments
 (0)