Skip to content

Commit 85bd4de

Browse files
committed
fix(apple): take the exec result type from host-kit and thin the fixture assertion body
#2689 derived the runner host port from the modules it fronts, so `ExecResult` is read from `@agent-device/host-kit/command` now rather than restated in `runner/host.ts`. The per-fixture assertion body had grown past the complexity the Fallow audit allows a changed file: the envelope checks move into `assertFailureEnvelope` and the tool-output check into `assertToolOutputReachable`, so each recorded shape is still asserted through the same path and the test body reads as one call.
1 parent 17631c6 commit 85bd4de

1 file changed

Lines changed: 45 additions & 25 deletions

File tree

‎packages/platform-apple/src/runner/__tests__/runner-startup-failure-reasons.test.ts‎

Lines changed: 45 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { afterEach, beforeEach, test, vi } from 'vitest';
55
import { AppError, normalizeError, type NormalizedError } from '@agent-device/kernel/errors';
66
import { resetAllProcessMemosForTests } from '@agent-device/kernel/ttl-memo';
77
import { appleRunnerTestHost } from '../test-host.ts';
8-
import type { ExecResult } from '../host.ts';
8+
import type { ExecResult } from '@agent-device/host-kit/command';
99
import { createRunnerPhaseBudget, ensureXctestrunArtifact } from '../runner-xctestrun.ts';
1010
import {
1111
RUNNER_ERROR_RULES,
@@ -92,33 +92,53 @@ afterEach(() => {
9292

9393
for (const fixture of buildForTestingFixtures()) {
9494
test(`a build-for-testing failure publishes ${fixture.reason} for ${fixture.id}`, async () => {
95-
const envelope = await driveBuildFailure(fixture);
96-
97-
assert.equal(envelope.code, 'COMMAND_FAILED');
98-
assert.equal(envelope.message, 'xcodebuild build-for-testing failed');
99-
assert.equal(envelope.details?.reason, fixture.reason);
100-
assert.match(String(envelope.hint), HINT_FOR_REASON[fixture.reason]);
101-
// No `logPath` was handed to `normalizeError`: the top-level value can only be the one the
102-
// build catch wrote into the error it throws.
103-
assert.equal(envelope.logPath, logPath);
104-
assert.equal(envelope.diagnosticId, DIAGNOSTIC_ID);
105-
// normalizeError hoists these out of `details`; a caller must read them at top level.
106-
assert.equal(envelope.details?.hint, undefined);
107-
assert.equal(envelope.details?.logPath, undefined);
108-
assert.equal(envelope.details?.diagnosticId, undefined);
109-
// The tool output stays reachable for a human reading the failure. It is redacted and
110-
// length-bounded on the way out, which is another reason the reason is typed: classification
111-
// happens before the truncation a caller sees. A message-only failure carries no tool output to
112-
// reach, which is exactly why the message is part of the haystack.
113-
if ((fixture.carrier ?? 'exec-details') === 'exec-details') {
114-
const nestedDetails = envelope.details?.details as Record<string, unknown> | undefined;
115-
assert.match(String(nestedDetails?.stdout), /AgentDeviceRunner/);
116-
} else {
117-
assert.equal(envelope.details?.details, undefined);
118-
}
95+
assertFailureEnvelope(await driveBuildFailure(fixture), fixture);
11996
});
12097
}
12198

99+
/**
100+
* Every startup failure reaches a caller through one envelope: the typed reason in `details`, its hint
101+
* and the log path hoisted to top level by `normalizeError`, and the tool output still reachable
102+
* underneath for a human. The envelope is asserted per fixture rather than once because the reason and
103+
* the hint have to travel together for every recorded shape, not just for one of them.
104+
*/
105+
function assertFailureEnvelope(
106+
envelope: NormalizedError,
107+
fixture: RunnerStartupFailureFixture,
108+
): void {
109+
assert.equal(envelope.code, 'COMMAND_FAILED');
110+
assert.equal(envelope.message, 'xcodebuild build-for-testing failed');
111+
assert.equal(envelope.details?.reason, fixture.reason);
112+
assert.match(String(envelope.hint), HINT_FOR_REASON[fixture.reason]);
113+
// No `logPath` was handed to `normalizeError`: the top-level value can only be the one the
114+
// build catch wrote into the error it throws.
115+
assert.equal(envelope.logPath, logPath);
116+
assert.equal(envelope.diagnosticId, DIAGNOSTIC_ID);
117+
// normalizeError hoists these out of `details`; a caller must read them at top level.
118+
assert.equal(envelope.details?.hint, undefined);
119+
assert.equal(envelope.details?.logPath, undefined);
120+
assert.equal(envelope.details?.diagnosticId, undefined);
121+
assertToolOutputReachable(envelope, fixture);
122+
}
123+
124+
/**
125+
* The tool output stays reachable for a human reading the failure, redacted and length-bounded on the
126+
* way out — one more reason the reason is typed: classification happens before the truncation a caller
127+
* sees. A message-only failure carries no tool output to reach, which is exactly why the message is
128+
* part of the haystack.
129+
*/
130+
function assertToolOutputReachable(
131+
envelope: NormalizedError,
132+
fixture: RunnerStartupFailureFixture,
133+
): void {
134+
if ((fixture.carrier ?? 'exec-details') !== 'exec-details') {
135+
assert.equal(envelope.details?.details, undefined);
136+
return;
137+
}
138+
const nestedDetails = envelope.details?.details as Record<string, unknown> | undefined;
139+
assert.match(String(nestedDetails?.stdout), /AgentDeviceRunner/);
140+
}
141+
122142
test('every startup failure reason has a recorded fixture', () => {
123143
const reasonsWithFixtures = new Set(RUNNER_STARTUP_FAILURE_FIXTURES.map((f) => f.reason));
124144

0 commit comments

Comments
 (0)