Skip to content

Commit 956cd37

Browse files
committed
diagnose(1874): route cadence evidence through a typed value-free boundary
logCommitCadence accepts Int lengths and a timestamp only, so observed field contents are unrepresentable at the poll call site; its emitted line is pinned by a sentinel-secret test in the host-lane policy tests. The source guard becomes structural — boundary present, poll path logs through it, no raw NSLog in the observe closure — instead of parsing Swift format strings. #1874 is reopened as the removal-tracking thread for this temporary instrumentation.
1 parent 3cb1a53 commit 956cd37

3 files changed

Lines changed: 99 additions & 50 deletions

File tree

‎apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SynthesizedTextEntry.swift‎

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,35 @@ extension RunnerTests {
201201
return length
202202
}
203203

204+
/// The emitted cadence line, as a pure function so its output is assertable. Only lengths and
205+
/// a timestamp are representable here; there is no String parameter, so observed field
206+
/// contents cannot reach runner.log through this boundary whatever they contain.
207+
static func commitCadenceLogLine(
208+
elapsedMs: Int,
209+
observedLen: Int,
210+
expectedPrefixLen: Int
211+
) -> String {
212+
"[DEBUG-1874] poll t=\(elapsedMs)ms observedLen=\(observedLen) expectedPrefixLen=\(expectedPrefixLen)"
213+
}
214+
215+
/// The typed boundary for commit-wait cadence evidence. The poll path must log through this
216+
/// function and never through a raw NSLog: every parameter is an Int, so the polled value's
217+
/// contents are unrepresentable at the call site.
218+
static func logCommitCadence(
219+
elapsedMs: Int,
220+
observedLen: Int,
221+
expectedPrefixLen: Int
222+
) {
223+
NSLog(
224+
"%@",
225+
commitCadenceLogLine(
226+
elapsedMs: elapsedMs,
227+
observedLen: observedLen,
228+
expectedPrefixLen: expectedPrefixLen
229+
)
230+
)
231+
}
232+
204233
/// How the commit wait ended. Distinct from `SynthesizedTextCommitProgress`, which classifies a
205234
/// single observation: this is the whole wait's verdict, and it exists so the deadline can be
206235
/// told apart from success. The wait used to return `Void`, which made an expired deadline
@@ -296,11 +325,10 @@ extension RunnerTests {
296325
// Cadence evidence stays value-free: the polled value is user content typed through
297326
// `type` and must never reach runner.log. Lengths and the expected-prefix walk are
298327
// enough to distinguish throttling (prefix grows slowly) from a wedge (it freezes).
299-
NSLog(
300-
"[DEBUG-1874] poll t=%.0fms observedLen=%ld expectedPrefixLen=%ld",
301-
waitStartedAt.timeIntervalSinceNow * -1000,
302-
observedText?.count ?? -1,
303-
observedText.map { Self.commonPrefixLength($0, expectedText) } ?? -1
328+
Self.logCommitCadence(
329+
elapsedMs: Int(waitStartedAt.timeIntervalSinceNow * -1000),
330+
observedLen: observedText?.count ?? -1,
331+
expectedPrefixLen: observedText.map { Self.commonPrefixLength($0, expectedText) } ?? -1
304332
)
305333
return observedText
306334
},

‎apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/UnitTests/RunnerTests+TextEntryPolicyTests.swift‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,20 @@ extension RunnerTests {
319319
XCTAssertEqual(Self.commonPrefixLength("hx", "hardware-keyboard"), 1)
320320
XCTAssertEqual(Self.commonPrefixLength("hardware-keyboarx", "hardware-keyboard"), 15)
321321
}
322+
323+
func testCommitCadenceLogLineEmitsLengthsOnlyNeverContents() {
324+
// Sentinel secret: even when the polled field holds credential-shaped content, the only
325+
// channel into runner.log is this line, and its inputs are lengths. The exact-equality
326+
// assert fails if any content-bearing parameter or interpolation is ever added.
327+
let secret = "hunter2-typed-credential"
328+
let line = Self.commitCadenceLogLine(
329+
elapsedMs: 42,
330+
observedLen: secret.count,
331+
expectedPrefixLen: 8
332+
)
333+
XCTAssertEqual(line, "[DEBUG-1874] poll t=42ms observedLen=24 expectedPrefixLen=8")
334+
XCTAssertFalse(line.contains(secret))
335+
}
322336
#endif
323337
#endif
324338
}

‎src/__tests__/apple-runner-log-redaction.test.ts‎

Lines changed: 52 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -12,58 +12,65 @@ const synthesizedTextEntryPath = path.join(
1212

1313
// The synthesized bare-type commit wait polls the target field's live value on the shipped
1414
// `type` path. That value is user content — a `type` command may carry credentials, tokens, or
15-
// PII — and runner.log persists across the session. Cadence evidence must stay value-free:
16-
// lengths, timestamps, and enum names only.
15+
// PII — and runner.log persists across the session. Cadence evidence must stay value-free.
1716
//
18-
// Guard shape: every NSLog format string in the module that interpolates a string (%@) must be
19-
// on this allowlist of static, non-field-content formats. Reintroducing raw observed text into
20-
// runner logging requires adding a new %@ format here, which fails this test until a human
21-
// reviews it.
22-
const allowedStringInterpolatingFormats = new Set([
23-
'AGENT_DEVICE_RUNNER_TEXT_ENTRY_ROUTE route=%@',
24-
'AGENT_DEVICE_RUNNER_TEXT_ENTRY_ROUTE route=verified-fallback reason=%@',
25-
'AGENT_DEVICE_RUNNER_TEXT_ENTRY_PHASE commandId=%@ phase=%@ durationMs=%.1f chars=%d mode=%@',
26-
'[DEBUG-1874] wait outcome=%@ elapsedMs=%.0f',
27-
]);
17+
// The enforcement is a typed Swift boundary (`logCommitCadence`), whose parameters are Ints
18+
// only, so observed contents are unrepresentable at the call site; its emitted line is pinned
19+
// by a sentinel-secret test in the host-lane policy tests. This guard is structural: it fails
20+
// if the boundary disappears or if the poll path logs any other way. It deliberately does not
21+
// parse Swift format strings — that review shape let raw values slip through interpolation.
2822

29-
function extractNSLogStatements(source: string): string[] {
30-
const statements: string[] = [];
31-
let index = source.indexOf('NSLog(');
32-
while (index !== -1) {
33-
let depth = 0;
34-
let cursor = index + 'NSLog'.length;
35-
for (; cursor < source.length; cursor += 1) {
36-
if (source[cursor] === '(') depth += 1;
37-
if (source[cursor] === ')') {
38-
depth -= 1;
39-
if (depth === 0) break;
40-
}
41-
}
42-
statements.push(source.slice(index, cursor + 1));
43-
index = source.indexOf('NSLog(', cursor);
44-
}
45-
return statements;
23+
const boundarySignature =
24+
/static func commitCadenceLogLine\(\s*elapsedMs: Int,\s*observedLen: Int,\s*expectedPrefixLen: Int\s*\) -> String/;
25+
const loggingBoundarySignature =
26+
/static func logCommitCadence\(\s*elapsedMs: Int,\s*observedLen: Int,\s*expectedPrefixLen: Int\s*\)/;
27+
28+
function extractObserveClosure(source: string): string {
29+
const start = source.indexOf('observe: {');
30+
assert.ok(start !== -1, 'commit wait must inject an observe closure');
31+
const end = source.indexOf('waitForNextObservation:', start);
32+
assert.ok(end !== -1, 'commit wait must keep its waitForNextObservation seam');
33+
return source.slice(start, end);
4634
}
4735

48-
test('synthesized text entry logging stays free of observed field contents', () => {
36+
test('commit-wait cadence logging goes through the typed value-free boundary', () => {
4937
const source = fs.readFileSync(synthesizedTextEntryPath, 'utf8');
50-
const statements = extractNSLogStatements(source);
51-
assert.ok(statements.length > 0, 'expected NSLog statements in the module');
52-
53-
for (const statement of statements) {
54-
const format = statement.match(/"((?:[^"\\]|\\.)*)"/)?.[1];
55-
assert.ok(format != null, `NSLog without a literal format string: ${statement}`);
56-
if (!format.includes('%@')) continue;
57-
assert.ok(
58-
allowedStringInterpolatingFormats.has(format),
59-
`unreviewed string-interpolating log format "${format}" — field contents must never reach runner.log`,
60-
);
61-
}
6238

63-
// The invariant this module must keep: cadence evidence names lengths, not contents.
6439
assert.match(
6540
source,
66-
/poll t=%\.0fms observedLen=%ld expectedPrefixLen=%ld/,
67-
'commit-wait polling must log value-free cadence evidence',
41+
boundarySignature,
42+
'commitCadenceLogLine must accept only lengths/timestamps (Int parameters)',
43+
);
44+
assert.match(
45+
source,
46+
loggingBoundarySignature,
47+
'logCommitCadence is the only sanctioned logging entry for the poll path',
6848
);
49+
50+
const observeClosure = extractObserveClosure(source);
51+
const directNSLogs = observeClosure.match(/NSLog\(/g) ?? [];
52+
assert.deepEqual(
53+
directNSLogs,
54+
[],
55+
'the poll path must log through logCommitCadence, never through a raw NSLog',
56+
);
57+
assert.match(
58+
observeClosure,
59+
/Self\.logCommitCadence\(/,
60+
'the poll path must emit its cadence evidence through the typed boundary',
61+
);
62+
63+
// Cheap extra: no NSLog anywhere in the module interpolates the raw observed binding.
64+
for (
65+
let index = source.indexOf('NSLog(');
66+
index !== -1;
67+
index = source.indexOf('NSLog(', index + 1)
68+
) {
69+
const window = source.slice(index, index + 400);
70+
assert.doesNotMatch(
71+
window,
72+
/NSLog\([^)]*\bobservedText\b/,
73+
'raw observedText must never reach NSLog',
74+
);
75+
}
6976
});

0 commit comments

Comments
 (0)