mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-04 14:28:41 +01:00
* feat(missions): derive guarded Continue Mission action from canonical project state * feat(missions): one-click Continue through existing permissioned project dispatch * feat(missions): expose authorized and state-gated next move in mission control * test(missions): guard resume action and reuse the authoritative project dispatch gate * docs(missions): state execution boundaries and known limitations of Continue Mission * chore(ci): temporarily emit canonical mission action formatter diff * style(missions): apply exact formatter output for Continue Mission * style(missions): apply exact formatter output for Continue Mission * chore(ci): restore full normal checks after exact mission formatting fix * fix(missions): escape JSX apostrophe in dispatch consent copy
69 lines
2.8 KiB
TypeScript
69 lines
2.8 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import { readFileSync } from "node:fs";
|
|
import { missionContinueOffer } from "@/lib/missions/continue-offer";
|
|
|
|
const base = {
|
|
canEdit: true,
|
|
buildStatus: "idle" as const,
|
|
hasRepo: true,
|
|
hasQueuedNextStep: true,
|
|
hasBriefOrGoals: true,
|
|
};
|
|
|
|
assert.deepEqual(missionContinueOffer(base), { type: "dispatch", kind: "next_step" });
|
|
assert.deepEqual(missionContinueOffer({ ...base, hasQueuedNextStep: false }), {
|
|
type: "dispatch",
|
|
kind: "kickoff",
|
|
});
|
|
assert.deepEqual(
|
|
missionContinueOffer({ ...base, hasQueuedNextStep: false, hasBriefOrGoals: false }),
|
|
{ type: "setup", reason: "no_brief" },
|
|
);
|
|
assert.deepEqual(missionContinueOffer({ ...base, hasRepo: false }), {
|
|
type: "setup",
|
|
reason: "no_repo",
|
|
});
|
|
assert.deepEqual(missionContinueOffer({ ...base, canEdit: false }), { type: "read_only" });
|
|
|
|
for (const state of ["building", "queued", "needs_you", "stalled"] as const) {
|
|
assert.deepEqual(
|
|
missionContinueOffer({ ...base, buildStatus: state }),
|
|
{ type: "watch", reason: state },
|
|
`do not dispatch over a ${state} run`,
|
|
);
|
|
assert.deepEqual(
|
|
missionContinueOffer({ ...base, buildStatus: state, hasRepo: false }),
|
|
{ type: "watch", reason: state },
|
|
"inspect active state before guessing setup failures",
|
|
);
|
|
}
|
|
assert.deepEqual(
|
|
missionContinueOffer({ ...base, canEdit: false, buildStatus: "building" }),
|
|
{ type: "read_only" },
|
|
"no interaction or leak of runtime detail for a view-only collaborator",
|
|
);
|
|
|
|
const page = readFileSync("src/app/(app)/missions/[id]/page.tsx", "utf8");
|
|
const action = readFileSync("src/components/missions/MissionContinueAction.tsx", "utf8");
|
|
const dispatchRoute = readFileSync("src/app/api/projects/[id]/dispatch/route.ts", "utf8");
|
|
const dispatchStep = readFileSync("src/lib/kickoff/steps.ts", "utf8");
|
|
|
|
assert.match(page, /getProjectDossier\(userId, id\)/);
|
|
assert.match(page, /getProjectAccess\(userId, id\)/);
|
|
assert.match(page, /deriveBuildStatus\(/);
|
|
assert.match(page, /missionContinueOffer\(/);
|
|
assert.match(page, /access\.ownerUserId === dossier\.ownerId/);
|
|
assert.match(action, /useProjectDispatch\(projectId\)/);
|
|
assert.match(action, /dispatch\(offer\.kind\)/);
|
|
assert.match(action, /disabled={state\.phase === "sending"}/);
|
|
assert.match(action, /router\.refresh\(\)/);
|
|
assert.doesNotMatch(action, /fetch\(/, "keep the existing project's dispatch client");
|
|
assert.match(dispatchRoute, /getApiUserId\(\)/);
|
|
assert.match(dispatchRoute, /dispatchStep\(userId, idOrResp, dataOrResp\)/);
|
|
assert.match(dispatchStep, /getProjectAccess\(userId, id\)/);
|
|
assert.match(dispatchStep, /if \(!access\.canEdit\)/);
|
|
assert.match(dispatchStep, /injectPrompt\(/);
|
|
assert.doesNotMatch(page + action, /export async function POST\(/);
|
|
|
|
console.log("✓ Mission continue: same permissioned dispatch, never double-dispatch an active run");
|