@@ -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+ / s t a t i c f u n c c o m m i t C a d e n c e L o g L i n e \( \s * e l a p s e d M s : I n t , \s * o b s e r v e d L e n : I n t , \s * e x p e c t e d P r e f i x L e n : I n t \s * \) - > S t r i n g / ;
25+ const loggingBoundarySignature =
26+ / s t a t i c f u n c l o g C o m m i t C a d e n c e \( \s * e l a p s e d M s : I n t , \s * o b s e r v e d L e n : I n t , \s * e x p e c t e d P r e f i x L e n : I n t \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- / p o l l t = % \. 0 f m s o b s e r v e d L e n = % l d e x p e c t e d P r e f i x L e n = % l d / ,
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 ( / N S L o g \( / 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+ / S e l f \. l o g C o m m i t C a d e n c e \( / ,
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+ / N S L o g \( [ ^ ) ] * \b o b s e r v e d T e x t \b / ,
73+ 'raw observedText must never reach NSLog' ,
74+ ) ;
75+ }
6976} ) ;
0 commit comments