Skip to content

Commit ec31963

Browse files
committed
review: drive error samples through the real producers; enforce local-help on the routing smoke
The DEVICE_IN_USE, AMBIGUOUS_MATCH, and APP_NOT_INSTALLED parity tests no longer hand-author the producer message before rendering: each drives the actual producer — buildDeviceInUseBySessionError (extracted in session-open.ts and called by the handler), buildAmbiguousMatchError (now exported from find.ts), and buildAppNotInstalledError (extracted in app-resolution.ts and thrown by the resolver). Because each factory is exported from its producer file and called by the production path, dropping the production call would make it test-only and fail check:production-exports — the wiring is gate-enforced, not conventional. open-and-snapshot now sets requireLocalCliHelp and allowOnlyLocalCliHelpCommands, so the 'skill plus local help' claim is observed rather than assumed; without them the case can pass on model prior alone.
1 parent f1bd373 commit ec31963

6 files changed

Lines changed: 67 additions & 23 deletions

File tree

‎scripts/__tests__/help-conformance-sample-outputs.test.ts‎

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ import {
1313
} from '../help-conformance-sample-outputs.mjs';
1414
import { interactionCliOutputFormatters } from '../../src/commands/interaction/output.ts';
1515
import { NEVER_SETTLED_HINT } from '../../src/commands/interaction/runtime/settle.ts';
16+
import { buildAmbiguousMatchError } from '../../src/daemon/handlers/find.ts';
1617
import { refMutationAdmissionResponse } from '../../src/daemon/handlers/interaction-ref-policy.ts';
17-
import { buildSessionRecoveryHint } from '../../src/daemon/session-recovery-hints.ts';
18+
import { buildDeviceInUseBySessionError } from '../../src/daemon/handlers/session-open.ts';
1819
import { resolveRefStalenessWarning } from '../../src/daemon/session-snapshot.ts';
1920
import type { SessionState } from '../../src/daemon/types.ts';
21+
import { buildAppNotInstalledError } from '../../src/platforms/apple/core/app-resolution.ts';
2022
import { AppError, normalizeError } from '../../src/kernel/errors.ts';
2123
import type { SnapshotQualityVerdict } from '../../src/snapshot/snapshot-quality.ts';
2224
import { renderSnapshotQualityWarnings } from '../../src/snapshot/snapshot-quality.ts';
@@ -154,13 +156,19 @@ test('private-ax recovery sample matches the snapshot renderer and quality warni
154156
assert.equal(text.trimEnd(), PRIVATE_AX_RECOVERY_SAMPLE.output);
155157
});
156158

157-
test('device-in-use sample matches the human error rendering and recovery hint', () => {
159+
test('device-in-use sample matches the real session-open producer', () => {
158160
const owningSession = { name: 'checkout' } as SessionState;
161+
const device = { id: 'SIM-001', name: 'iPhone 17 Pro' } as Parameters<
162+
typeof buildDeviceInUseBySessionError
163+
>[1];
164+
const response = buildDeviceInUseBySessionError(owningSession, device);
165+
assert.ok(!response.ok, 'the by-session conflict must be an error response');
159166
const rendered = renderHumanError(
160-
new AppError('DEVICE_IN_USE', 'Device is already in use by session "checkout".', {
161-
session: 'checkout',
162-
hint: buildSessionRecoveryHint(owningSession, 'device-in-use'),
163-
}),
167+
new AppError(
168+
response.error.code as ConstructorParameters<typeof AppError>[0],
169+
response.error.message,
170+
response.error.details,
171+
),
164172
);
165173
assert.equal(rendered, DEVICE_IN_USE_SAMPLE.output);
166174
});
@@ -184,19 +192,25 @@ test('stale-ref sample matches the real admission rejection and staleness hint',
184192
assert.equal(rendered, STALE_REF_SAMPLE.output);
185193
});
186194

187-
test('ambiguous-match sample matches the human error rendering and default hint', () => {
195+
test('ambiguous-match sample matches the real find producer and default hint', () => {
196+
const matches = [
197+
{ ref: 'e2', label: 'Follow' },
198+
{ ref: 'e5', label: 'Follow' },
199+
{ ref: 'e9', label: 'Follow' },
200+
] as Parameters<typeof buildAmbiguousMatchError>[0];
201+
const response = buildAmbiguousMatchError(matches, 'text', 'Follow');
202+
assert.ok(!response.ok, 'an ambiguous find must be an error response');
188203
const rendered = renderHumanError(
189204
new AppError(
190-
'AMBIGUOUS_MATCH',
191-
'find matched 3 elements for text "Follow". Use a more specific locator or selector.',
205+
response.error.code as ConstructorParameters<typeof AppError>[0],
206+
response.error.message,
207+
response.error.details,
192208
),
193209
);
194210
assert.equal(rendered, AMBIGUOUS_MATCH_SAMPLE.output);
195211
});
196212

197-
test('app-not-installed sample matches the human error rendering and default hint', () => {
198-
const rendered = renderHumanError(
199-
new AppError('APP_NOT_INSTALLED', 'No app found matching "Shoply"'),
200-
);
213+
test('app-not-installed sample matches the real app-resolution producer and default hint', () => {
214+
const rendered = renderHumanError(buildAppNotInstalledError('Shoply'));
201215
assert.equal(rendered, APP_NOT_INSTALLED_SAMPLE.output);
202216
});

‎scripts/help-conformance-sample-outputs.mjs‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,9 @@ Detected an overly complex or slow accessibility tree. Fell back to the private-
6464
@e8 [tab] "Home" [selected]`,
6565
};
6666

67-
// DEVICE_IN_USE from src/daemon/handlers/session-open.ts: another session owns
68-
// the device; the hint is buildSessionRecoveryHint(session, 'device-in-use').
67+
// DEVICE_IN_USE from buildDeviceInUseBySessionError
68+
// (src/daemon/handlers/session-open.ts) — the parity test drives that exact
69+
// producer.
6970
export const DEVICE_IN_USE_SAMPLE = {
7071
command: `agent-device press 'label="Place order"' --settle`,
7172
output: `Error (DEVICE_IN_USE): Device is already in use by session "checkout".
@@ -83,18 +84,20 @@ export const STALE_REF_SAMPLE = {
8384
Hint: Ref @e12 was minted from snapshot s5 but the session's ref frame is now s7 — re-run snapshot -i.`,
8485
};
8586

86-
// AMBIGUOUS_MATCH from src/daemon/handlers/find.ts buildAmbiguousMatchError;
87-
// the by-design rejection instead of silent disambiguation. Candidate refs
88-
// live in details, which the human rendering does not print — the agent must
89-
// re-observe or narrow, not guess a ref it never saw.
87+
// AMBIGUOUS_MATCH from buildAmbiguousMatchError (src/daemon/handlers/find.ts)
88+
// — the parity test drives that exact producer. The by-design rejection
89+
// instead of silent disambiguation: candidate refs live in details, which the
90+
// human rendering does not print, so the agent must re-observe or narrow, not
91+
// guess a ref it never saw.
9092
export const AMBIGUOUS_MATCH_SAMPLE = {
9193
command: 'agent-device find text "Follow" press',
9294
output: `Error (AMBIGUOUS_MATCH): find matched 3 elements for text "Follow". Use a more specific locator or selector.
9395
Hint: Multiple candidates matched. Narrow the query or pass an exact identifier.`,
9496
};
9597

96-
// APP_NOT_INSTALLED from src/platforms/apple/core/app-resolution.ts; the hint
97-
// is defaultHintForCode('APP_NOT_INSTALLED').
98+
// APP_NOT_INSTALLED from buildAppNotInstalledError
99+
// (src/platforms/apple/core/app-resolution.ts) — the parity test drives that
100+
// exact producer; the hint is defaultHintForCode('APP_NOT_INSTALLED').
98101
export const APP_NOT_INSTALLED_SAMPLE = {
99102
command: 'agent-device open Shoply --platform ios',
100103
output: `Error (APP_NOT_INSTALLED): No app found matching "Shoply"

‎src/daemon/handlers/find.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,10 @@ function publicFindFlags(flags: DaemonRequest['flags']): Record<string, unknown>
542542
return { ...(stripInternalInteractionFlags(flags) ?? {}) };
543543
}
544544

545-
function buildAmbiguousMatchError(
545+
// Exported as the single AMBIGUOUS_MATCH producer so the help-benchmark
546+
// sample parity test renders the exact error this handler returns; a message
547+
// change here fails that gate instead of drifting past it.
548+
export function buildAmbiguousMatchError(
546549
matches: SnapshotState['nodes'],
547550
locator: FindLocator,
548551
query: string,

‎src/daemon/handlers/session-open.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,17 @@ function findNewSessionDeviceConflict(params: {
559559
},
560560
);
561561
}
562+
return buildDeviceInUseBySessionError(inUse, device);
563+
}
564+
565+
// Exported as the single by-session DEVICE_IN_USE producer so the
566+
// help-benchmark sample parity test renders the exact error this handler
567+
// returns; a message or hint change here fails that gate instead of drifting
568+
// past it.
569+
export function buildDeviceInUseBySessionError(
570+
inUse: SessionState,
571+
device: DeviceInfo,
572+
): DaemonResponse {
562573
return errorResponse('DEVICE_IN_USE', `Device is already in use by session "${inUse.name}".`, {
563574
session: inUse.name,
564575
deviceId: device.id,

‎src/platforms/apple/core/app-resolution.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,14 @@ export async function resolveIosApp(device: DeviceInfo, app: string): Promise<st
5959
throw new AppError('INVALID_ARGS', `Multiple apps matched "${app}"`, { matches });
6060
}
6161

62-
throw new AppError('APP_NOT_INSTALLED', `No app found matching "${app}"`);
62+
throw buildAppNotInstalledError(app);
63+
}
64+
65+
// Exported as the single name-lookup APP_NOT_INSTALLED producer so the
66+
// help-benchmark sample parity test renders the exact error this resolver
67+
// throws; a message change here fails that gate instead of drifting past it.
68+
export function buildAppNotInstalledError(app: string): AppError {
69+
return new AppError('APP_NOT_INSTALLED', `No app found matching "${app}"`);
6370
}
6471

6572
/**

‎test/skillgym/suites/agent-device-smoke-suite.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,12 @@ const FIXTURE_SMOKE_CASES: Case[] = [
345345
/host\.exp\.Exponent/i,
346346
/exp:\/\/127\.0\.0\.1:8081/i,
347347
],
348+
// The suite's claim is "a sane plan from the skill plus local help" — so
349+
// the run must actually consult local help, and must not execute anything
350+
// else while planning. Without these, the case can pass on model prior
351+
// alone and the claim is unproven.
352+
allowOnlyLocalCliHelpCommands: true,
353+
requireLocalCliHelp: true,
348354
}),
349355
];
350356

0 commit comments

Comments
 (0)