import test from 'node:test'; import assert from 'node:assert/strict'; import fs from 'node:fs'; import path from 'node:path'; import {fixture} from './helpers.mjs'; import {createDeliveryProject,applyDeliveryFix,deliveryGit} from './fixtures/delivery-project.mjs'; import {CheckRunner} from '../src/core/check-runner.mjs'; import {taskDeliveryProgress} from '../src/core/context/delivery-progress.mjs'; test('reviewed application invalidates old checks, names current SHA and advances through a new approved check to Git preview',async t=>{ const f=fixture(t),run=createDeliveryProject(f),checks=new CheckRunner(f.store);f.onCleanup(()=>checks.stopAll()); const snapshot=()=>taskDeliveryProgress(f.store,f.session,run,{checks}); assert.equal(await snapshot(),null);const before=deliveryGit(f,['rev-parse','HEAD']); const original=await checks.plan(f.session);await(await checks.start(f.session,original.id)).promise; applyDeliveryFix(f);let progress=await snapshot();assert.equal(progress.stage,'needs_current_check_plan'); assert.equal(progress.latest_check.stale,true);assert.ok(progress.files.every(file=>file.current&&file.current_sha256===file.applied_sha256)); assert.deepEqual(progress.next_action,{tool:'plan_checks',arguments:{names:['test','build']}}); const plan=await checks.plan(f.session);progress=await snapshot();assert.equal(progress.stage,'ready_for_checks'); assert.deepEqual(progress.next_action,{tool:'run_checks',arguments:{plan_id:plan.id}});assert.equal(f.store.core.check_job.size,1,'snapshot never executes a check'); const passed=await(await checks.start(f.session,plan.id)).promise;assert.equal(passed.status,'passed'); progress=await snapshot();assert.equal(progress.stage,'ready_for_git_preview');assert.equal(progress.latest_check.current_source,true); assert.equal(progress.next_action.tool,'plan_delivery');assert.equal(deliveryGit(f,['rev-parse','HEAD']),before,'snapshot cannot publish a commit'); fs.appendFileSync(path.join(f.projectRoot,'src/math.mjs'),'// owner changed\n');progress=await snapshot(); assert.equal(progress.stage,'applied_files_need_review');assert.equal(progress.next_action,null);assert.equal(progress.files.find(file=>file.path==='src/math.mjs').current,false); }); test('skip-tests, foreign task, unknown operations, diagnostic and parent review retain their boundaries',async t=>{ const f=fixture(t),run=createDeliveryProject(f),checks=new CheckRunner(f.store);f.onCleanup(()=>checks.stopAll());applyDeliveryFix(f); const task=f.store.core.task.get(f.session.taskId);task.contract={...task.contract,checks:'skip'}; const snapshot=options=>taskDeliveryProgress(f.store,f.session,run,{checks,...options}); assert.equal((await snapshot()).stage,'checks_not_requested');assert.equal((await snapshot()).next_action.tool,'delivery_report'); assert.equal((await snapshot({worker:true})).next_action,null);assert.equal(f.store.core.check_plan.size,0); assert.equal(await taskDeliveryProgress(f.store,f.session,{...run,purpose:'diagnostic'},{checks}),null); f.session.changes[0].taskId='foreign-task';assert.equal((await snapshot()).files.length,1); const id='owned-unknown';f.store.core.tool.set(id,{id,sessionId:f.session.id,projectId:f.project.id,taskId:task.id,requiresVerification:true}); assert.equal((await snapshot()).stage,'awaiting_review_or_verification');assert.equal((await snapshot()).next_action,null); });