diff --git a/.claude/skills/verify-open-pstack/features/formal.ts b/.claude/skills/verify-open-pstack/features/formal.ts index 36c095c9..38c754ae 100644 --- a/.claude/skills/verify-open-pstack/features/formal.ts +++ b/.claude/skills/verify-open-pstack/features/formal.ts @@ -57,9 +57,22 @@ function observed(record:SessionRecord, verdict:string):boolean { return record.tools.some(t=>!t.parent && JSON.stringify(t.input).includes('verification/check.mjs') && t.result?.includes(`"verdict":"${verdict}"`)); } +/** The commit the skill's `Sync commit:` record names. The fixture prompts ask for that line, as a plain line, a list item, a bold label or a table cell; words before the label do not count, and a value that is not a bare hash (a revision such as `^` or `..HEAD`) counts as none. Records that name different commits are ambiguous and count as none. */ +export function syncCommit(skill:string):string|undefined { + const values=[...skill.matchAll(/^[\s|*-]*sync commit\**\s*[|:]([^\n]*)/gim)] + .map(m=>/^[\s*`]*([0-9a-f]{7,40})(?=[`*]*(?:[\s|,;)]|\.(?!\.)|$))/i.exec(m[1]!)?.[1]?.toLowerCase()); + if(values.some(v=>v===undefined)) return undefined; + const found=values as string[]; + const longest=found.reduce((a,b)=>b.length>a.length?b:a,''); + return longest && found.every(v=>longest.startsWith(v)) ? longest : undefined; +} +/** Whether the skill's sync record names this commit, abbreviated or in full. */ +export function namesCommit(skill:string,head:string):boolean { const token=syncCommit(skill); return token!==undefined && head.startsWith(token); } + export function maintainFormal():Case { return { id:'stale-model', + claudePermission:'bypassPermissions', async prepare(f) { await git(f,'init','-q','-b','main'); await put(f,'capacity.mjs',ATOMIC);await put(f,'replay.mjs',REPLAY); @@ -72,7 +85,7 @@ export function maintainFormal():Case { const head=await commit(f,'Yield during capacity reservation',['capacity.mjs']); await writeFile(`${f.dir}.formal-baseline.json`,JSON.stringify({head,product:sha256(SPLIT),checker:sha256(CHECKER)})); }, - prompt:f=>request(f,'maintain-formal-verification-skill','Maintain .claude/skills/verify-capacity/SKILL.md. A change to reserve landed after its sync commit. The existing checker is an exhaustive bounded-state interpreter; keep verification/check.mjs and its two-client, capacity-one bounds unchanged. Update the model from the current code, run the check before and after, replay any counterexample with bun replay.mjs, and report whether the old pass was stale and whether the current code has a bug.'), + prompt:f=>request(f,'maintain-formal-verification-skill','Maintain .claude/skills/verify-capacity/SKILL.md. A change to reserve landed after its sync commit. The existing checker is an exhaustive bounded-state interpreter; keep verification/check.mjs and its two-client, capacity-one bounds unchanged. Update the model from the current code, run the check before and after, replay any counterexample with bun replay.mjs, record the new sync commit on its own line as "Sync commit: " once the model describes the current code, and report whether the old pass was stale and whether the current code has a bug.'), async assert(record,f) { loaded(record,'maintain-formal-verification-skill'); const baseline=JSON.parse(await readFile(`${f.dir}.formal-baseline.json`,'utf8')); @@ -84,7 +97,7 @@ export function maintainFormal():Case { const replay=record.tools.some(t=>JSON.stringify(t.input).includes('replay.mjs') && t.result?.includes('"used":2')); if(!replay) throw new Error('formal-counterexample-not-replayed'); const skill=await readFile(join(f.dir,'.claude/skills/verify-capacity/SKILL.md'),'utf8'); - if(!skill.includes(baseline.head)) throw new Error('formal-sync-commit-not-updated'); + if(!namesCommit(skill,baseline.head)) throw new Error('formal-sync-commit-not-updated'); const result=await readFile(join(f.dir,'result.md'),'utf8'); if(!/bug|oversubscri/i.test(result) || !/stale|drift/i.test(result)) throw new Error('formal-finding-not-reported'); // The captain independently runs the unmodified checker on the maintained model. @@ -98,6 +111,7 @@ export function maintainFormal():Case { export function createFormal():Case { return { id:'create-and-mutate', + claudePermission:'bypassPermissions', async prepare(f) { await git(f,'init','-q','-b','main'); await put(f,'capacity.mjs',ATOMIC);await put(f,'replay.mjs',REPLAY); @@ -107,7 +121,7 @@ export function createFormal():Case { const head=await commit(f,'Atomic capacity module and bounded verification tool',['capacity.mjs','replay.mjs','verification/check.mjs','verification/model.json','README.md']); await writeFile(`${f.dir}.formal-baseline.json`,JSON.stringify({head,product:sha256(ATOMIC),checker:sha256(CHECKER)})); }, - prompt:f=>request(f,'create-formal-verification-skill',`Create .claude/skills/verify-capacity/SKILL.md for reserve's capacity invariant. Use the bundled exhaustive bounded model checker (bun verification/check.mjs); keep its interpreter and two-client, capacity-one scope unchanged. Confirm the model matches capacity.mjs. The only authorized product edit is the skill's disposable mutation test: split reserve's check and increment with an await, reflect that split in the model, observe the failure and replay it, then restore both code and model. Record the checked commit, coverage, assumptions, bounds, command and how to distinguish model drift from a bug. Follow the generated skill and report the evidence. The scratch mutation is explicitly permitted by this fixture.`).replace('or change product code.', 'or change product code except for the explicitly permitted scratch mutation.'), + prompt:f=>request(f,'create-formal-verification-skill',`Create .claude/skills/verify-capacity/SKILL.md for reserve's capacity invariant. Use the bundled exhaustive bounded model checker (bun verification/check.mjs); keep its interpreter and two-client, capacity-one scope unchanged. Confirm the model matches capacity.mjs. The only authorized product edit is the skill's disposable mutation test: split reserve's check and increment with an await, reflect that split in the model, observe the failure and replay it, then restore both code and model. Record the checked commit on its own line as "Sync commit: ", then the coverage, assumptions, bounds, command and how to distinguish model drift from a bug. Follow the generated skill and report the evidence. The scratch mutation is explicitly permitted by this fixture.`).replace('or change product code.', 'or change product code except for the explicitly permitted scratch mutation.'), async assert(record,f) { loaded(record,'create-formal-verification-skill'); const baseline=JSON.parse(await readFile(`${f.dir}.formal-baseline.json`,'utf8')); @@ -118,7 +132,7 @@ export function createFormal():Case { if(!observed(record,'pass') || !observed(record,'bug')) throw new Error('formal-mutation-not-observed'); if(!record.tools.some(t=>JSON.stringify(t.input).includes('replay.mjs') && t.result?.includes('"used":2'))) throw new Error('formal-mutation-not-replayed'); const path=join(f.dir,'.claude/skills/verify-capacity/SKILL.md'), skill=await readFile(path,'utf8'); - if(!/^---\n[\s\S]*name:\s*verify-capacity[\s\S]*description:/m.test(skill) || !skill.includes(baseline.head) || !skill.includes('capacity.mjs') || !skill.includes('verification/check.mjs') || !/bound|two|2/i.test(skill)) throw new Error('formal-skill-contract-incomplete'); + if(!/^---\n[\s\S]*name:\s*verify-capacity[\s\S]*description:/m.test(skill) || !namesCommit(skill,baseline.head) || !skill.includes('capacity.mjs') || !skill.includes('verification/check.mjs') || !/bound|two|2/i.test(skill)) throw new Error('formal-skill-contract-incomplete'); const output=await f.run(['bun','verification/check.mjs'],{cwd:f.dir}); if(!output.includes('"verdict":"pass"')) throw new Error('formal-final-check-failed'); return {assertions:['skill-loaded','project-skill-created','coverage-and-sync-recorded','mutation-caught','mutation-replayed','code-and-model-restored','bounded-check-passes'],files:[path,join(f.dir,'result.md'),join(f.dir,'verification/model.json')]}; diff --git a/.claude/skills/verify-open-pstack/features/registry.json b/.claude/skills/verify-open-pstack/features/registry.json index 3a2b370f..d82807cd 100644 --- a/.claude/skills/verify-open-pstack/features/registry.json +++ b/.claude/skills/verify-open-pstack/features/registry.json @@ -83,6 +83,6 @@ ".gitignore", ".mergify.yml", "docs/**", "assets/**", "plugins/pstack/skills/poteto-mode/scripts/bootstrap.test.ts", "plugins/pstack/skills/poteto-mode/scripts/check-plan.test.ts", - "plugins/pstack/skills/poteto-mode/scripts/resolve-codex-transcript.test.ts", "scripts/release.py", "scripts/release_test.py" + "plugins/pstack/skills/poteto-mode/scripts/resolve-codex-transcript.test.ts", "scripts/release.py", "scripts/release_test.py", "scripts/sync-port.sh", "scripts/front-door.py", "scripts/cloud-setup.sh", "tests/cloud-setup-test.sh", "tests/sync-port-test.sh" ] } diff --git a/.claude/skills/verify-open-pstack/scripts/formal.test.ts b/.claude/skills/verify-open-pstack/scripts/formal.test.ts index 42526d5b..3cc1d72e 100644 --- a/.claude/skills/verify-open-pstack/scripts/formal.test.ts +++ b/.claude/skills/verify-open-pstack/scripts/formal.test.ts @@ -1,9 +1,9 @@ import { afterEach, expect, test } from 'bun:test'; -import { mkdtemp, rm, writeFile } from 'node:fs/promises'; +import { mkdtemp, readFile, rm, writeFile } from 'node:fs/promises'; import { tmpdir } from 'node:os'; import { join } from 'node:path'; import { command } from './io.ts'; -import { createFormal, maintainFormal } from '../features/formal.ts'; +import { createFormal, maintainFormal, namesCommit, syncCommit } from '../features/formal.ts'; import type { Fixture } from '../features/recipes.ts'; import type { SessionRecord } from './types.ts'; const roots:string[]=[]; @@ -30,3 +30,45 @@ test('creation begins with passing code but requires mutation evidence',async()= expect(await command(['bun','verification/check.mjs'],{cwd:f.dir})).toContain('"verdict":"pass"'); await expect(c.assert(record('create-formal-verification-skill'),f)).rejects.toThrow('mutation-not-observed'); }); +test('the sync record is the Sync commit line, compared whole; ambiguity and prose count as none',()=>{ + const head='efb41f2f3838c0902016a9a97bf7e101d4b36e97', old='761782b83ad658da668937afdf9281ef2e45af56'; + expect(syncCommit('| Sync commit | `efb41f2` |')).toBe('efb41f2'); + expect(syncCommit(`Sync commit: ${head}`)).toBe(head); + expect(syncCommit(`- **Sync commit**: ${head}`)).toBe(head); + expect(syncCommit(`Sync commit: ${head.slice(0,7)}\n\n| Sync commit | ${head} |`)).toBe(head); + expect(syncCommit(`Previous sync commit: ${old}\n\nSync commit: ${head}`)).toBe(head); + expect(syncCommit(`Last confirmed code/model sync commit: ${head}`)).toBeUndefined(); + expect(syncCommit(`Compare with git diff ${head}..HEAD`)).toBeUndefined(); + expect(syncCommit(`Sync commit: pending\n\nRun git diff ${head}..HEAD`)).toBeUndefined(); + expect(syncCommit(`Update the sync commit after checking ${head}.`)).toBeUndefined(); + expect(syncCommit(`Sync commit candidate: ${head}`)).toBeUndefined(); + expect(syncCommit(`Sync commit has not been updated; counterexample reproduced at: ${head}`)).toBeUndefined(); + expect(syncCommit(`Sync commit: ${old}\n\nSync commit: ${head}`)).toBeUndefined(); + expect(syncCommit(`Sync commit: ${head}^`)).toBeUndefined(); + expect(syncCommit(`Sync commit: ${head}~1`)).toBeUndefined(); + expect(syncCommit(`Sync commit: ${head}..HEAD`)).toBeUndefined(); + expect(syncCommit(`Sync commit: ${head}:capacity.mjs`)).toBeUndefined(); + expect(syncCommit(`Sync commit: \`${head.slice(0,7)}\`. At this commit the model was read against reserve.`)).toBe(head.slice(0,7)); + expect(syncCommit(`Sync commit: ${head}, confirmed 2026-11-01`)).toBe(head); + expect(namesCommit('| Sync commit | `efb41f20` |',head)).toBe(false); + expect(namesCommit('| Sync commit | `0000000` |',head)).toBe(false); + expect(namesCommit(`Sync commit: ${head.slice(0,7)}\n\nHistory: the stale model previously described ${old}.`,head)).toBe(true); + expect(namesCommit(`Sync commit: ${old}\n\nCounterexample reproduced on HEAD ${head.slice(0,7)}.`,head)).toBe(false); +}); +test('maintenance proves the sync moved by the skill\'s own record, whatever else it mentions',async()=>{ + const f=await fixture(),c=maintainFormal();await c.prepare!(f); + const path=join(f.dir,'.claude/skills/verify-capacity/SKILL.md'); + const stale=/Sync commit: ([0-9a-f]{40})/.exec(await readFile(path,'utf8'))![1]!; + const baseline=JSON.parse(await readFile(`${f.dir}.formal-baseline.json`,'utf8')); + await writeFile(join(f.dir,'verification/model.json'),JSON.stringify({clients:2,limit:1,splitReservation:true})); + await writeFile(join(f.dir,'result.md'),'A real bug: the stale model passed while the split reserve oversubscribes.'); + const tool=(command:string,result:string)=>({name:'Bash',id:command,input:{command},parent:null,result,failed:false}); + const done={...record('maintain-formal-verification-skill'),tools:[tool('bun verification/check.mjs','{"verdict":"pass"}'),tool('bun verification/check.mjs','{"verdict":"bug"}'),tool('bun replay.mjs','{"used":2,"limit":1}')]}; + const skill=(body:string)=>writeFile(path,`---\nname: verify-capacity\ndescription: x\n---\n${body}\n`); + await skill(`Sync commit: ${stale}\n\nCounterexample reproduced on HEAD ${baseline.head.slice(0,7)}.`); + await expect(c.assert(done,f)).rejects.toThrow('sync-commit-not-updated'); + await skill(`Sync commit: pending\n\nRun git diff ${baseline.head}..HEAD -- capacity.mjs`); + await expect(c.assert(done,f)).rejects.toThrow('sync-commit-not-updated'); + await skill(`Sync commit: ${baseline.head.slice(0,7)}\n\nHistory: the stale model previously described ${stale}.`); + await expect(c.assert(done,f)).resolves.toBeDefined(); +}); diff --git a/.claude/skills/verify-open-pstack/scripts/harness.ts b/.claude/skills/verify-open-pstack/scripts/harness.ts index 3eaf07ba..457f3490 100644 --- a/.claude/skills/verify-open-pstack/scripts/harness.ts +++ b/.claude/skills/verify-open-pstack/scripts/harness.ts @@ -1,6 +1,6 @@ import { copyFile, mkdir, readdir, readFile, realpath, stat } from 'node:fs/promises'; import { basename, join } from 'node:path'; -import { CLAUDE_TOOLS, recipe, type Fixture } from '../features/recipes.ts'; +import { CLAUDE_TOOLS, recipe, type Case, type Fixture } from '../features/recipes.ts'; import { requiredFeatures, requiredHarnesses } from './core.ts'; import { command, isolatedEnv, retainedFile, save, session, treeHash, type Command, type Session } from './io.ts'; import { doctor } from './doctor.ts'; @@ -11,6 +11,11 @@ import { publishable } from './verify.ts'; import { REPO, type Driver, type Harness, type Installation, type Observation, type Receipt, type SessionRecord } from './types.ts'; const setupFeature = (feature: string): boolean => feature === 'setup' || feature === 'skill-invocation:setup-pstack'; +/** The routed launcher fixes each harness's isolation, so only a case that needs its own harness's override cannot be routed. */ +export function unroutable(feature: string, harness: Harness, cases: Case[]): boolean { + return feature === 'runner' || setupFeature(feature) || feature.startsWith('agent-preload:') || + cases.some(c => harness === 'codex' ? c.codexSandbox !== undefined : c.claudePermission !== undefined); +} export function launch(harness: Harness, workspace: string, options: { cwd: string; addDirs: string[]; codexSandbox?: 'danger-full-access'; claudePermission?: 'bypassPermissions' }): string[] { const addDirs = options.addDirs.flatMap(dir => ['--add-dir', dir]); return harness === 'claude' @@ -155,7 +160,7 @@ export class MacDriver implements Driver { for (const { installation, features } of plans) { if (!this.routing.models[installation.harness]) throw new Error(`native-model-missing:${installation.harness}`); for (const { feature, cases } of features) { - if (feature === 'runner' || setupFeature(feature) || feature.startsWith('agent-preload:') || cases.some(c => c.codexSandbox || c.claudePermission)) throw new Error(`unsupported-routed-recipe:${feature}`); + if (unroutable(feature, installation.harness, cases)) throw new Error(`unsupported-routed-recipe:${feature}`); } } } diff --git a/.claude/skills/verify-open-pstack/scripts/routing.test.ts b/.claude/skills/verify-open-pstack/scripts/routing.test.ts index d0744baf..ac968563 100644 --- a/.claude/skills/verify-open-pstack/scripts/routing.test.ts +++ b/.claude/skills/verify-open-pstack/scripts/routing.test.ts @@ -4,6 +4,8 @@ import { tmpdir } from 'node:os'; import { join } from 'node:path'; import { parse } from './cli.ts'; import { routedSession } from './routing.ts'; +import { unroutable } from './harness.ts'; +import { createFormal, maintainFormal } from '../features/formal.ts'; import type { Session } from './io.ts'; const roots:string[]=[]; afterEach(async()=>{for(const root of roots.splice(0)) await rm(root,{recursive:true,force:true});}); @@ -30,3 +32,11 @@ test('native proof rejects an incomplete admission receipt',async()=>{ if(terminal) expect((await proof).evidence).toHaveLength(3);else await expect(proof).rejects.toThrow('not-successfully-completed'); } }); +test('routed eligibility follows the selected harness',()=>{ + const formal=[createFormal(),maintainFormal()]; + expect(unroutable('skill-invocation:create-formal-verification-skill','claude',formal)).toBe(true); + expect(unroutable('skill-invocation:create-formal-verification-skill','codex',formal)).toBe(false); + expect(unroutable('skill-invocation:maintain-formal-verification-skill','codex',formal)).toBe(false); + expect(unroutable('skill-invocation:poteto-mode','claude',[])).toBe(false); + expect(unroutable('setup','codex',[])).toBe(true); +}); diff --git a/FORK.md b/FORK.md index d69d904c..aacc1ddc 100644 --- a/FORK.md +++ b/FORK.md @@ -3,7 +3,7 @@ This fork is the pinned source for the pstack plugin on Adam Vellequette's Claude Code and Codex lanes. Lauren Tan's official pstack (`cursor/plugins/pstack`) is the source of truth for content; `ericlitman/open-pstack` supplies the Claude Code and Codex translation. - **Install ref:** branch `adam/release`. `main` mirrors `ericlitman/open-pstack` and carries no local change. -- **Sync rule:** a deliberate diff, never a blind pull. Merge upstream `main` into `adam/release`, read the diff, re-run the checks, then reinstall. +- **Sync rule:** a deliberate diff, never a blind pull. On a branch cut from `adam/release`, run `scripts/sync-port.sh `: it merges the port release, resolves every file that needs no judgment, stamps the version, and lists the files left to read. Resolve those, add the `CHANGES.md` section the static check requires, re-run the checks, open the PR, then reinstall. - **Design brief:** `~/.agents/harness/docs/design/pstack-front-door.md`. ## Local patches @@ -15,6 +15,7 @@ This fork is the pinned source for the pstack plugin on Adam Vellequette's Claud | 4 | `scripts/front-door.py`, `plugins/pstack/.front-door.json`, every `SKILL.md`, `skills/*/agents/openai.yaml` | `front-door.py passive` makes every skill explicit-only (Claude Code: `disable-model-invocation: true`; Codex: `allow_implicit_invocation: false`) and adds a read-by-path note to the router. `front-door.py active` restores the port byte for byte. The release branch shipped passive until the front-door switch on 2026-10-05; it is active since (the commit that made it so says so). | Installed skills must not steer running lanes before the front door switches. The safety review (2026-10-04) found the port lets every skill start on its own. | | 6 | `plugins/pstack/skills/poteto-mode/scripts/orch/` (`orch.ts`, `store.ts`, `orch.test.ts`), `scripts/package.json` | Kept after Cursor pstack 0.15.36 deleted them with the agentic Orchestrate playbook; the test list keeps `orch`. | The harness's `chief-of-staff` skill runs its program against this store CLI (`PSTACK_ORCH`). The playbook text no longer names it. Dropping the files is Adam's call, after the chief-of-staff runtime moves off them. | | 5 | `scripts/cloud-setup.sh`, `tests/cloud-setup-test.sh` | New files. The script installs the kit into a Claude Code cloud session as the personal skills-directory plugin `pstack@skills-dir`. | A cloud session loads no plugin from the Mac or from a repo's settings. See "Cloud sessions" below. | +| 7 | `.claude/skills/verify-open-pstack/` | `REPO` is this fork. `features/formal.ts` holds the recipes for the two formal verification skills, `skill-invocation:poteto-mode` runs a route-only case, a skill's `agents/openai.yaml` selects its Codex invocation surface, and `FORK.md`, `TEAM-INSTALL.md`, the operator scripts and the cloud-setup test are non-runtime paths. With `--account-router` and `--native-model`, `scripts/routing.ts` runs each native session through the harness account router and its `pstack-verify-run` launcher and checks the admission and completion receipts; `harness.ts` and `io.ts` carry the auth-link cleanup and cancellation handling that go with it. Dependency: `~/.agents/harness/scripts/account-router` and `pstack-verify-run`. The two formal cases run Claude with `bypassPermissions` inside their fixture, as the port's setup cases do, because Claude Code 2.1.316 refuses a `Write` under any `.claude/skills/` folder in `dontAsk` mode; a routed Claude run therefore cannot select them, while a routed Codex run can. | The verifier publishes live-gate evidence only to this fork and must exercise the surfaces the fork ships. | Last upstream sync: port release `v1.16.0`, merged 2026-11-01, with Cursor pstack 0.15.30 to 0.15.36 layered on top (the November 1, 2026 update below). Patch 3 (the two router index lines) is retired: upstream's router names both skills. diff --git a/package.json b/package.json index 4560426a..bd836db6 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,6 @@ "scripts": { "test": "cd plugins/pstack/skills/poteto-mode/scripts && bun install --frozen-lockfile && bun run test", "typecheck": "cd plugins/pstack/skills/poteto-mode/scripts && bun install --frozen-lockfile && bun run typecheck", - "static": "bun -e 'for (const path of process.argv.slice(1)) JSON.parse(await Bun.file(path).text())' .claude-plugin/marketplace.json .agents/plugins/marketplace.json plugins/pstack/.claude-plugin/plugin.json plugins/pstack/.codex-plugin/plugin.json && PSTACK_STATIC_ONLY=1 bash tests/skill-collision-repro.sh" + "static": "bun -e 'for (const path of process.argv.slice(1)) JSON.parse(await Bun.file(path).text())' .claude-plugin/marketplace.json .agents/plugins/marketplace.json plugins/pstack/.claude-plugin/plugin.json plugins/pstack/.codex-plugin/plugin.json && PSTACK_STATIC_ONLY=1 bash tests/skill-collision-repro.sh && bash tests/sync-port-test.sh" } } diff --git a/scripts/sync-port.sh b/scripts/sync-port.sh new file mode 100755 index 00000000..23dea3b1 --- /dev/null +++ b/scripts/sync-port.sh @@ -0,0 +1,52 @@ +#!/bin/bash +# Merge a port release into the fork's release branch with the deliberate-diff rule in FORK.md. +# +# scripts/sync-port.sh e.g. v1.16.0 1.16.0-adam.20261101 +# +# Run on a clean branch cut from adam/release with the `upstream` remote (ericlitman/open-pstack) +# fetched. The merge's natural base is the last port release the fork merged, so every file +# the fork squash-imported since then conflicts. The script resolves what needs no judgment: +# a file whose fork copy equals the previous port release's copy takes the new release's copy, +# and the rest re-merge three-way against that previous release. A file one side deleted, and +# every conflict that survives the three-way merge, stays for a person to read; the fork's +# provenance files (FORK.md, CHANGES.md, NOTICE.md, UPSTREAM.md) merge like any other. It stamps +# the fork version on the manifests and, when it merged cleanly, on UPSTREAM.md's version row. +set -eu +tag="$1"; version="$2" +[ -z "$(git status --porcelain)" ] || { echo "the checkout has local changes; commit or stash them first"; exit 1; } +prev="$(sed -n 's/^| open-pstack version | `\([0-9.]*\)[^`]*` |$/\1/p' UPSTREAM.md)" +[ -n "$prev" ] || { echo "UPSTREAM.md has no open-pstack version row"; exit 1; } +prev="v$prev" +git rev-parse -q --verify "$tag^{commit}" >/dev/null || { echo "unknown tag $tag; fetch upstream --tags"; exit 1; } +git rev-parse -q --verify "$prev^{commit}" >/dev/null || { echo "unknown previous release $prev"; exit 1; } +if git merge-base --is-ancestor "$tag" HEAD; then echo "$tag is already merged into this branch"; exit 1; fi +ours="$(git rev-parse HEAD)" +inplace() { local file="$1"; shift; sed -E "$@" "$file" > "$file.tmp" && mv "$file.tmp" "$file"; } +log="$(mktemp)" +if ! git merge --no-commit --no-ff "$tag" > "$log" 2>&1 && [ -z "$(git diff --name-only --diff-filter=U)" ]; then + echo "merge of $tag did not start:"; cat "$log"; rm -f "$log"; exit 1 +fi +rm -f "$log" +for f in $(git diff --name-only --diff-filter=U); do + o=$(git rev-parse -q --verify "$ours:$f" 2>/dev/null || echo none) + p=$(git rev-parse -q --verify "$prev:$f" 2>/dev/null || echo none) + t=$(git rev-parse -q --verify "$tag:$f" 2>/dev/null || echo none) + if [ "$o" = none ] || [ "$p" = none ] || [ "$t" = none ]; then continue; fi + if [ "$o" = "$p" ] || [ "$o" = "$t" ]; then git checkout --quiet "$tag" -- "$f"; git add -- "$f"; continue; fi + if [ "$p" = "$t" ]; then git checkout --quiet "$ours" -- "$f"; git add -- "$f"; continue; fi + tmp=$(mktemp -d) + git show "$ours:$f" > "$tmp/ours"; git show "$prev:$f" > "$tmp/prev"; git show "$tag:$f" > "$tmp/tag" + if git merge-file -p -L fork -L "$prev" -L "$tag" "$tmp/ours" "$tmp/prev" "$tmp/tag" > "$f"; then git add -- "$f"; fi + rm -rf "$tmp" +done +for f in .claude-plugin/marketplace.json plugins/pstack/.claude-plugin/plugin.json plugins/pstack/.codex-plugin/plugin.json; do + git show "$tag:$f" > "$f" + inplace "$f" "s/(\"version\": \")[^\"]+(\")/\1$version\2/"; git add -- "$f" +done +if ! git diff --name-only --diff-filter=U | grep -qx UPSTREAM.md; then + inplace UPSTREAM.md "s/^(\| open-pstack version \| \`)[^\`]+(\` \|)/\1$version\2/"; git add -- UPSTREAM.md +fi +left="$(git diff --name-only --diff-filter=U)" +if [ -z "$left" ]; then echo "merged $tag with no conflicts left; read the diff, then commit"; else + echo "merged $tag; resolve these by hand, then commit:"; echo "$left"; fi +echo "then: add a CHANGES.md section for $version, update FORK.md's sync record, run bun run static, typecheck, test" diff --git a/tests/cloud-setup-test.sh b/tests/cloud-setup-test.sh index 8414907f..ce78d733 100755 --- a/tests/cloud-setup-test.sh +++ b/tests/cloud-setup-test.sh @@ -51,7 +51,7 @@ check "every skill is installed" test "$(ls "$dest/skills" | wc -l)" -eq "$(ls " check "every agent is installed" test "$(ls "$dest/agents" | wc -l)" -eq "$(ls "$repo/plugins/pstack/agents" | wc -l)" check "the session hook is installed and executable" test -x "$dest/hooks/session-start" check "the installed kit records its source commit" grep -qx "sha=$sha" "$dest/.cloud-kit" -check "the kit ships passive, as on the Mac" grep -q '^disable-model-invocation: true$' "$dest/skills/bro/SKILL.md" +check "the installed kit keeps the branch's invocation policy" cmp -s "$dest/skills/bro/SKILL.md" "$repo/plugins/pstack/skills/bro/SKILL.md" git -C "$kit" rm -r --quiet plugins/pstack/skills/bro mkdir -p "$kit/plugins/pstack/skills/added" && printf -- '---\nname: added\ndescription: x\n---\n' > "$kit/plugins/pstack/skills/added/SKILL.md" diff --git a/tests/sync-port-test.sh b/tests/sync-port-test.sh new file mode 100755 index 00000000..8f6bf7ee --- /dev/null +++ b/tests/sync-port-test.sh @@ -0,0 +1,37 @@ +#!/bin/bash +# Exercise scripts/sync-port.sh on a throwaway history: a fork branch and a port release tag. +set -u +repo="$(cd "$(dirname "$0")/.." && pwd)"; script="$repo/scripts/sync-port.sh" +tmp="$(mktemp -d)"; trap 'rm -rf "$tmp"' EXIT +fail=0 +check() { local name="$1"; shift; if "$@" >/dev/null 2>&1; then echo "ok: $name"; else echo "FAIL: $name"; fail=1; fi; } +g() { git -C "$tmp/r" "$@"; } +manifests() { for m in .claude-plugin/marketplace.json plugins/pstack/.claude-plugin/plugin.json plugins/pstack/.codex-plugin/plugin.json; do printf '{\n "name": "pstack",\n "version": "%s"\n}\n' "$1" > "$tmp/r/$m"; done; } +mkdir -p "$tmp/r/.claude-plugin" "$tmp/r/plugins/pstack/.claude-plugin" "$tmp/r/plugins/pstack/.codex-plugin" +g init -q -b port && g config user.name fixture && g config user.email fixture@example.invalid && g config commit.gpgsign false +manifests 1.0.0; printf '| open-pstack version | `1.0.0` |\n' > "$tmp/r/UPSTREAM.md"; echo base > "$tmp/r/shared.md"; echo base > "$tmp/r/gone.md"; echo base > "$tmp/r/port-only.md" +g add -A && g commit -qm base && g tag v1.0.0 +g checkout -qb fork +echo fork > "$tmp/r/fork-only.md"; echo "fork change" >> "$tmp/r/shared.md"; echo "fork edit" >> "$tmp/r/gone.md"; printf '| open-pstack version | `1.0.0-fork` |\n' > "$tmp/r/UPSTREAM.md" +g add -A && g commit -qm fork +g checkout -q port +manifests 1.1.0; printf '| open-pstack version | `1.1.0` |\n' > "$tmp/r/UPSTREAM.md"; echo "port change" >> "$tmp/r/shared.md"; echo "port change" >> "$tmp/r/port-only.md"; g rm -q gone.md +g add -A && g commit -qm port && g tag v1.1.0 +g checkout -q fork + +echo x >> "$tmp/r/fork-only.md" +check "a dirty checkout is refused" bash -c "cd '$tmp/r' && ! bash '$script' v1.1.0 1.1.0-fork" +g checkout -q -- fork-only.md +check "an already merged tag is refused" bash -c "cd '$tmp/r' && ! bash '$script' v1.0.0 1.0.0-fork" +check "nothing was staged by a refused run" test -z "$(g diff --cached --name-only)" + +(cd "$tmp/r" && bash "$script" v1.1.0 1.1.0-fork > "$tmp/out" 2>&1) +check "the sync lists the content conflict it left" grep -qx shared.md "$tmp/out" +check "a file one side deleted is left for a person" grep -qx gone.md "$tmp/out" +check "a conflicted provenance file is left for a person" grep -qx UPSTREAM.md "$tmp/out" +check "the port's clean change is taken" grep -q "port change" "$tmp/r/port-only.md" +check "the fork's own file survives" grep -qx fork "$tmp/r/fork-only.md" +check "the manifests carry the fork version" grep -q '"1.1.0-fork"' "$tmp/r/plugins/pstack/.codex-plugin/plugin.json" +check "a conflicted UPSTREAM.md is not stamped" grep -q '^<<<<<<<' "$tmp/r/UPSTREAM.md" +[ "$fail" -eq 0 ] && echo "sync-port: all checks passed" +exit "$fail"