@@ -1209,6 +1209,162 @@ test('durable candidate validation supports pre-implementation and later repair
12091209 )
12101210} )
12111211
1212+ test ( 'default checkpoint restore ignores hidden-untracked config and rejects concealed index state' , async ( ) => {
1213+ const parent = await mkdtemp ( path . join ( os . tmpdir ( ) , 'echo-ui-restore-cleanliness-test-' ) )
1214+ const repository = path . join ( parent , 'repository' )
1215+ const worktree = path . join ( parent , 'worktree' )
1216+ const loopRoot = path . join ( worktree , 'loops' , 'issue-dev-loop' )
1217+ const git = async ( cwd , ...args ) => execFileAsync ( 'git' , args , { cwd } )
1218+ try {
1219+ await mkdir ( path . join ( repository , 'loops' , 'issue-dev-loop' ) , { recursive : true } )
1220+ await writeFile ( path . join ( repository , 'tracked.txt' ) , 'tracked\n' , 'utf8' )
1221+ await writeFile (
1222+ path . join ( repository , 'loops' , 'issue-dev-loop' , '.gitkeep' ) ,
1223+ '' ,
1224+ 'utf8' ,
1225+ )
1226+ await git ( repository , 'init' , '--initial-branch=dev' )
1227+ await git ( repository , 'config' , 'user.name' , 'Loop Test' )
1228+ await git ( repository , 'config' , 'user.email' , 'loop-test@example.invalid' )
1229+ await git ( repository , 'add' , '.' )
1230+ await git ( repository , 'commit' , '-m' , 'base' )
1231+ const baseSha = ( await git ( repository , 'rev-parse' , 'HEAD' ) ) . stdout . trim ( )
1232+ await git ( repository , 'worktree' , 'add' , '-b' , 'codex/issue-444' , worktree , baseSha )
1233+
1234+ const startedAt = '2026-07-24T00:00:00.000Z'
1235+ const record = {
1236+ schemaVersion : 1 ,
1237+ kind : 'active-checkpoint' ,
1238+ run : {
1239+ schemaVersion : 1 ,
1240+ runId : 'restore-untracked-run' ,
1241+ issueNumber : 444 ,
1242+ issueTitle : 'Restore exact durable worktree' ,
1243+ issueUrl : 'https://github.com/codeacme17/echo-ui/issues/444' ,
1244+ baseBranch : 'dev' ,
1245+ baseSha,
1246+ branch : 'codex/issue-444' ,
1247+ status : 'running' ,
1248+ startedAt,
1249+ finishedAt : null ,
1250+ prUrl : null ,
1251+ headSha : null ,
1252+ mergeSha : null ,
1253+ issueSnapshot : {
1254+ title : 'Restore exact durable worktree' ,
1255+ body : 'Fixture' ,
1256+ labels : [ 'codex-ready' ] ,
1257+ url : 'https://github.com/codeacme17/echo-ui/issues/444' ,
1258+ capturedAt : startedAt ,
1259+ } ,
1260+ briefDigest : null ,
1261+ uiEvidenceRequired : false ,
1262+ implementationCommit : null ,
1263+ } ,
1264+ briefSource : '' ,
1265+ events : [
1266+ {
1267+ schemaVersion : 1 ,
1268+ runId : 'restore-untracked-run' ,
1269+ type : 'loop_started' ,
1270+ timestamp : startedAt ,
1271+ status : 'running' ,
1272+ payload : { issueNumber : 444 , branch : 'codex/issue-444' } ,
1273+ } ,
1274+ ] ,
1275+ artifacts : [ ] ,
1276+ updatedAt : startedAt ,
1277+ }
1278+ const checkpoint = { record, commentUrl : null , createdAt : startedAt }
1279+
1280+ const restoredPreImplementation = await restoreActiveCheckpoint ( { loopRoot, checkpoint } )
1281+ assert . equal ( restoredPreImplementation . implementationCommit , null )
1282+ for ( const directory of [ 'logs' , 'handoffs' , 'screen-shots' , 'evidence' ] ) {
1283+ await rm ( path . join ( loopRoot , directory ) , { recursive : true , force : true } )
1284+ }
1285+
1286+ await git ( worktree , 'config' , 'status.showUntrackedFiles' , 'no' )
1287+ await writeFile ( path . join ( worktree , 'hidden-untracked.txt' ) , 'not clean\n' , 'utf8' )
1288+ const configuredStatus = await git ( worktree , 'status' , '--porcelain' )
1289+ assert . equal ( configuredStatus . stdout , '' )
1290+ await assert . rejects (
1291+ restoreActiveCheckpoint ( { loopRoot, checkpoint } ) ,
1292+ / c l e a n i s o l a t e d w o r k t r e e / ,
1293+ )
1294+
1295+ await rm ( path . join ( worktree , 'hidden-untracked.txt' ) )
1296+ await git ( worktree , 'update-index' , '--skip-worktree' , 'tracked.txt' )
1297+ await assert . rejects (
1298+ restoreActiveCheckpoint ( { loopRoot, checkpoint } ) ,
1299+ / i n d e x c o n c e a l m e n t / ,
1300+ )
1301+
1302+ await git ( worktree , 'update-index' , '--no-skip-worktree' , 'tracked.txt' )
1303+ await writeFile ( path . join ( worktree , 'tracked.txt' ) , 'repaired\n' , 'utf8' )
1304+ await git ( worktree , 'add' , 'tracked.txt' )
1305+ await git ( worktree , 'commit' , '-m' , 'repair implementation' )
1306+ const repairCommit = ( await git ( worktree , 'rev-parse' , 'HEAD' ) ) . stdout . trim ( )
1307+ const repairBrief = 'Repair the issue and retain the durable resume boundary.\n'
1308+ const repairBriefDigest = createHash ( 'sha256' ) . update ( repairBrief ) . digest ( 'hex' )
1309+ const repairResult = {
1310+ schemaVersion : 1 ,
1311+ runId : record . run . runId ,
1312+ agent : '$implement' ,
1313+ invocationId : 'repair-invocation' ,
1314+ startedAt : '2026-07-24T00:01:00.000Z' ,
1315+ finishedAt : '2026-07-24T00:02:00.000Z' ,
1316+ briefDigest : repairBriefDigest ,
1317+ commitSha : repairCommit ,
1318+ checks : [ { command : 'pnpm verify' , status : 'passed' } ] ,
1319+ }
1320+ const repairResultSource = `${ JSON . stringify ( repairResult ) } \n`
1321+ const repairResultDigest = createHash ( 'sha256' )
1322+ . update ( repairResultSource )
1323+ . digest ( 'hex' )
1324+ const repairResultPath = `logs/runs/${ record . run . runId } /repair-result.json`
1325+ const repairFinishedAt = repairResult . finishedAt
1326+ const repairRecord = structuredClone ( record )
1327+ repairRecord . run . implementationCommit = repairCommit
1328+ repairRecord . run . briefDigest = repairBriefDigest
1329+ repairRecord . briefSource = repairBrief
1330+ repairRecord . events . push ( {
1331+ schemaVersion : 1 ,
1332+ runId : record . run . runId ,
1333+ type : 'implementation_completed' ,
1334+ timestamp : repairFinishedAt ,
1335+ status : 'passed' ,
1336+ payload : {
1337+ agent : '$implement' ,
1338+ invocationId : repairResult . invocationId ,
1339+ startedAt : repairResult . startedAt ,
1340+ finishedAt : repairFinishedAt ,
1341+ briefDigest : repairBriefDigest ,
1342+ commitSha : repairCommit ,
1343+ resultPath : repairResultPath ,
1344+ resultDigest : repairResultDigest ,
1345+ } ,
1346+ } )
1347+ repairRecord . artifacts . push ( {
1348+ path : repairResultPath ,
1349+ sha256 : repairResultDigest ,
1350+ source : repairResultSource ,
1351+ } )
1352+ repairRecord . updatedAt = repairFinishedAt
1353+
1354+ const restoredRepair = await restoreActiveCheckpoint ( {
1355+ loopRoot,
1356+ checkpoint : {
1357+ record : repairRecord ,
1358+ commentUrl : null ,
1359+ createdAt : repairFinishedAt ,
1360+ } ,
1361+ } )
1362+ assert . equal ( restoredRepair . implementationCommit , repairCommit )
1363+ } finally {
1364+ await rm ( parent , { recursive : true , force : true } )
1365+ }
1366+ } )
1367+
12121368test ( 'review publication digest excludes assigned review URLs but binds review content' , ( ) => {
12131369 const review = {
12141370 schemaVersion : 1 ,
0 commit comments