Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 0 additions & 26 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,29 +71,3 @@ jobs:
- name: Check that the gate admits and owns its command's descendants
shell: bash
run: bash scripts/gate-check.sh "$RUNNER_TEMP/quest-lifecycle-install/bin/quest"

windows:
name: native Windows (${{ matrix.runner }})
if: github.event_name != 'pull_request'
strategy:
fail-fast: false
matrix:
runner: [windows-2022, windows-11-arm]
runs-on: ${{ matrix.runner }}
timeout-minutes: 15
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
# Nix doesn't run here; package.json's packageManager pins the flake's Bun.
- uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0
with:
bun-version-file: package.json
- run: bun install --frozen-lockfile
- name: Check CLI and core
run: bun run check
- name: Run the core and CLI suite
run: bun run test
- run: bun run build
- name: Verify native setup and removal without symlinks
run: bun scripts/lifecycle-check.mjs dist/quest.js
44 changes: 44 additions & 0 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Windows

# The native Windows suite runs nightly on main, outside pull requests and the
# merge queue, so a Windows regression may land and the next run catches it.
# GitHub reports a failed scheduled run only to the account that last changed
# the cron schedule (with Actions notifications on), not to the repository's
# watchers; that is the maintainer, whose account lands the workflow.
on:
schedule:
- cron: "23 8 * * *"
workflow_dispatch:

permissions:
contents: read

concurrency:
group: windows-${{ github.ref }}
cancel-in-progress: true

jobs:
windows:
name: native Windows (${{ matrix.runner }})
strategy:
fail-fast: false
matrix:
runner: [windows-2022, windows-11-arm]
runs-on: ${{ matrix.runner }}
timeout-minutes: 15
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
# Nix doesn't run here; package.json's packageManager pins the flake's Bun.
- uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0
with:
bun-version-file: package.json
- run: bun install --frozen-lockfile
- name: Check CLI and core
run: bun run check
- name: Run the core and CLI suite
run: bun run test
- run: bun run build
- name: Verify native setup and removal without symlinks
run: bun scripts/lifecycle-check.mjs dist/quest.js
1 change: 0 additions & 1 deletion quest/m1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,5 @@ earlier "Later work" milestone became m2.
- [Launch material](/quest/m1/launch.md) - README, quickstart, demo, comparison, and launch-post drafts
- [Workers in a 5-minute cache](/quest/m1/worker-cache.md) - re-plan #276's worker/coordinator split and gate tickets, after confirming the cache premise
- [Retire Decisions needed](/quest/m1/decisions-needed.md) - only `## Waiting` hands a draft back, once no open draft uses the old heading
- [Native Windows suite](/quest/m1/windows-suite.md) - the native Windows jobs pass, running nightly and on dispatch instead of on every push
- [Bun EFAULT report](/quest/m1/bun-efault.md) - report concurrent `rmSync` `EFAULT` on Windows, and drop the workaround once Bun fixes it
- [Review harness check](/quest/m1/review-harness.md) - recurring each milestone: newest pinned review models, and the live sandbox test passes
77 changes: 0 additions & 77 deletions quest/m1/windows-suite.md

This file was deleted.

11 changes: 9 additions & 2 deletions src/cli/worktree-hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,13 @@ function pullRequest(cwd: string, name: string): string | undefined {
return git(cwd, "rev-parse", "--verify", "--quiet", `${local}^{commit}`);
}

/** The checkout whose submodule `checkout` is, or undefined for a top-level one. */
function superproject(checkout: string): string | undefined {
// Git prints it with forward slashes on Windows, so canonical paths compare against it.
const path = git(checkout, "rev-parse", "--show-superproject-working-tree");
return path ? canonical(path) : undefined;
}

/** Claude's name for a workflow agent's worktree, `<run ID>-<agent number>`, which carries no agent ID. */
const WORKFLOW_CHECKOUT = /^wf_[0-9a-f]{8}-[0-9a-f]{3}-[0-9]+$/;

Expand All @@ -142,7 +149,7 @@ async function subagentCheckout(worktrees: Worktrees, input: HookInput): Promise
while (path && !record) {
const checkout = path;
record = await waiting(() => worktrees.registered(checkout));
path = git(checkout, "rev-parse", "--show-superproject-working-tree") || undefined;
path = superproject(checkout);
}
const agent = field(input, "agent_id");
if (record?.name === `agent-${agent}`) return record;
Expand Down Expand Up @@ -178,7 +185,7 @@ export async function claudeHook(
const main = mainCheckout(project);
let enclosing = cwd;
while (mainCheckout(enclosing) !== main) {
const parent = git(enclosing, "rev-parse", "--show-superproject-working-tree");
const parent = superproject(enclosing);
if (!parent) break;
enclosing = parent;
}
Expand Down
31 changes: 22 additions & 9 deletions src/cli/worktree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,26 @@ function changes(root: string, ignored: boolean): string[] {
.split("\0")
.filter(Boolean);
}
/** Initialized submodule checkouts, including nested ones. NULs preserve spaces and newlines. */
function submodules(root: string): string[] {
return git(root, "submodule", "foreach", "--quiet", "--recursive", 'printf "%s\\0" "$toplevel/$sm_path"')
/** The repository's submodule paths from its index, initialized or not. */
function gitlinks(repository: string): string[] {
const paths = git(repository, "ls-files", "--stage", "-z")
.split("\0")
.filter(Boolean)
.map(canonical);
.filter((record) => record.startsWith("160000 "))
.map((record) => join(repository, record.slice(record.indexOf("\t") + 1)));
// A conflicted gitlink has an entry per stage.
return [...new Set(paths)];
}
/**
* Initialized submodule checkouts, each followed by its own nested ones. Read from the index, since
* `git submodule` is a shell script that costs seconds on Windows.
*/
function submodules(root: string): string[] {
return gitlinks(root)
.filter((path) => existsSync(join(path, ".git")))
.flatMap((path) => {
const module = canonical(path);
return [module, ...submodules(module)];
});
}

/** Module stores survive deinit; removing this worktree deletes their refs too. */
Expand All @@ -257,9 +271,7 @@ function clean(root: string): { modules: string[]; stores: Set<string> } {
const found = changes(root, false);
if (found.length) throw new Error(`checkout has modified or untracked files: ${found.slice(0, 20).join(", ")}`);
for (const repository of [root, ...modules]) {
for (const record of git(repository, "ls-files", "--stage", "-z").split("\0")) {
if (!record.startsWith("160000 ")) continue;
const path = join(repository, record.slice(record.indexOf("\t") + 1));
for (const path of gitlinks(repository)) {
if (entry(path)?.isDirectory() && !existsSync(join(path, ".git")) && readdirSync(path).length)
throw new Error(`uninitialized submodule contains files: ${path}`);
}
Expand Down Expand Up @@ -637,7 +649,8 @@ export class Worktrees {
});
try {
// Cloning can need the network; the reservation stays charged without holding the shared lock.
await gitAsync(record.path, "submodule", "update", "--init", "--recursive");
if (gitlinks(record.path).length)
await gitAsync(record.path, "submodule", "update", "--init", "--recursive");
for (const module of submodules(record.path)) {
const untracked = (ref: string) => git(module, "rev-list", "-n1", ref, "--not", "--remotes").trim();
const fetch = (refs: string[]) =>
Expand Down
7 changes: 4 additions & 3 deletions test/move.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,8 @@ describe("quest check --fix", () => {

/**
* A feature branch that adds quest three linking one and two, while main makes `change`;
* returns the tree checked out on the feature branch, before any merge.
* returns the tree checked out on the feature branch, before any merge. Checking out the
* feature branch writes quest three with CRLF where core.autocrlf is set, as on Windows runners.
*/
async function diverged(change: (tree: Tree) => Promise<void> | void): Promise<Tree> {
const tree = Tree.committed();
Expand Down Expand Up @@ -379,7 +380,7 @@ describe("quest check --fix", () => {

const out = await quest(tree, "check", "--fix");
expect(out).toEqual({ code: 0, stdout: "M quest/m0/epic/three.md\nquest: 5 documents ok\n", stderr: "" });
expect(tree.read("quest/m0/epic/three.md")).toBe(
expect(tree.read("quest/m0/epic/three.md").replaceAll("\r\n", "\n")).toBe(
"# [S] Three\n\n## Goal\n\nMore.\n\n## Related\n\n- [Two](/quest/m0/epic/two.md) - similar\n",
);
// The edit is left for the merge's author to stage.
Expand Down Expand Up @@ -407,7 +408,7 @@ describe("quest check --fix", () => {
const out = await quest(tree, "check", "--fix");
expect(out.code).toBe(1);
expect(out.stdout).toBe("M quest/m0/epic/README.md\nM quest/m0/epic/second.md\nM quest/m0/epic/three.md\n");
expect(tree.read("quest/m0/epic/three.md")).toBe(
expect(tree.read("quest/m0/epic/three.md").replaceAll("\r\n", "\n")).toBe(
"# [S] Three\n\n## Goal\n\nMore.\n\n## Related\n\n- [Two](/quest/m0/epic/two.md) - similar\n" +
"- [Nope](/quest/m0/epic/nope.md)\n\n## Plan\n\nAfter [one](/quest/m0/epic/one.md).\n",
);
Expand Down
4 changes: 2 additions & 2 deletions test/runner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
symlinkSync,
writeFileSync,
} from "node:fs";
import { dirname, join, resolve } from "node:path";
import { delimiter, dirname, join, resolve } from "node:path";
import { pathToFileURL } from "node:url";
import { describe, expect, test, vi } from "vitest";

Expand Down Expand Up @@ -2355,7 +2355,7 @@ describe("runner reviews", () => {
env: {
...env,
CLAUDE_CONFIG_DIR: "/runner/accounts/claude",
PATH: "/nix/store/claude/bin:/usr/bin",
PATH: ["/nix/store/claude/bin", "/usr/bin"].join(delimiter),
},
});
expect(() => reviewerFor(openai, [openai, limited], home, env, 1000)).toThrow(Unreviewable);
Expand Down
26 changes: 17 additions & 9 deletions test/worktree.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ afterEach(() => {

// Cases run up to 20 real Git processes. Process creation on the Windows ARM runner
// costs ~80-250 ms while other test files start, so the 5 s unit-test default is too short.
// Cases that create checkouts with submodules clone each nested repository, running
// 100-300 Git processes, so they get 60 s.
describe("worktrees", { timeout: 20_000 }, () => {
it("prunes declared scratch in place and keeps source, Git state, and untracked files", async () => {
const { repo, worktrees } = fixture();
Expand Down Expand Up @@ -316,7 +318,8 @@ describe("worktrees", { timeout: 20_000 }, () => {
git(repo, "commit", "-am", "submodule");
const record = await worktrees.create(repo, "nested", 10_000_000, "HEAD", ["sub/nested/inner/cache"]);
const nested = join(record.path, "sub", "nested", "inner");
expect(readFileSync(join(nested, "file"), "utf8")).toBe("original\n");
// Git checks text out with CRLF where core.autocrlf is set, as on Windows runners.
expect(readFileSync(join(nested, "file"), "utf8").replaceAll("\r\n", "\n")).toBe("original\n");
const direct = (await claudeHook(
{ hook_event_name: "WorktreeCreate", cwd: nested, name: "direct" },
worktrees,
Expand Down Expand Up @@ -369,7 +372,7 @@ describe("worktrees", { timeout: 20_000 }, () => {
worktrees.restore(record.id);
expect(existsSync(join(nested, "cache"))).toBe(false);
expect(readFileSync(join(nested, "file"), "utf8")).toBe("local work");
});
}, 60_000);
it("ignores inherited Git location variables that select a submodule", async () => {
const { root, repo, worktrees } = fixture();
vi.stubEnv("GIT_ALLOW_PROTOCOL", "file");
Expand All @@ -389,14 +392,14 @@ describe("worktrees", { timeout: 20_000 }, () => {
repo,
))!.trim();
expect(path).toBe(join(canonical(repo), ".worktrees", "agent-located"));
expect(readFileSync(join(path, "sub", "file"), "utf8")).toBe("original\n");
expect(readFileSync(join(path, "sub", "file"), "utf8").replaceAll("\r\n", "\n")).toBe("original\n");
const [record] = worktrees.status().records;
expect(record.repository).toBe(canonical(repo));
// Removal inspects the checkout itself, not the submodule the variables name.
writeFileSync(join(path, "file"), "local work");
await expect(worktrees.remove(record.id)).rejects.toThrow("checkout has modified or untracked files: M file");
expect(readFileSync(join(path, "file"), "utf8")).toBe("local work");
});
}, 60_000);
it("charges cloned module stores and keeps one that serves another worktree", async () => {
const { root, repo, worktrees } = fixture();
vi.stubEnv("GIT_ALLOW_PROTOCOL", "file");
Expand All @@ -418,7 +421,7 @@ describe("worktrees", { timeout: 20_000 }, () => {
git(join(record.path, "sub"), "worktree", "remove", elsewhere);
await worktrees.remove(record.id);
expect(existsSync(record.path)).toBe(false);
});
}, 60_000);
it("protects a live creation without giving interrupted-checkout removal advice", async () => {
const { repo, worktrees } = fixture();
const creation = worktrees.create(repo, "live", 10_000_000);
Expand Down Expand Up @@ -448,7 +451,7 @@ describe("worktrees", { timeout: 20_000 }, () => {
}
await worktrees.remove(record.id);
expect(existsSync(record.path)).toBe(false);
});
}, 60_000);
it("keeps a partly initialized creation charged and gives recovery advice for its lock and submodules", async () => {
const { root, repo, worktrees } = fixture();
vi.stubEnv("GIT_ALLOW_PROTOCOL", "file");
Expand All @@ -466,7 +469,7 @@ describe("worktrees", { timeout: 20_000 }, () => {
expect(() => worktrees.release(record.id)).toThrow("git worktree unlock");
expect(() => worktrees.release(record.id)).toThrow("--force for submodules");
expect(worktrees.status().allocated).toBe(10_000_000);
});
}, 60_000);
it("keeps nested submodule files and commits, including branches whose HEAD is back at the pin", async () => {
const { root, repo, worktrees } = fixture();
vi.stubEnv("GIT_ALLOW_PROTOCOL", "file");
Expand Down Expand Up @@ -530,7 +533,7 @@ describe("worktrees", { timeout: 20_000 }, () => {
);
await worktrees.remove(record.id);
expect(existsSync(record.path)).toBe(false);
});
}, 60_000);
it("serializes reservations across independent repositories and preserves failed allocations", async () => {
const { root, repo, home, worktrees } = fixture();
const second = repository(join(root, "second"));
Expand Down Expand Up @@ -781,7 +784,12 @@ describe("supervised runs", { timeout: 20_000 }, () => {
it.skipIf(process.platform === "linux")("fails explicitly without a supported backend", async () => {
const { repo, home } = fixture();
vi.stubEnv("QUEST_WORKTREE_HOME", home);
expect(run("--root", repo, "worktree", "create", "cli", "--reserve", "10000000").code).toBe(0);
expect(
await main(["--root", repo, "worktree", "create", "cli", "--reserve", "10000000"], {
stdout: () => {},
stderr: () => {},
}),
).toBe(0);
let stderr = "";
const code = await main(["worktree", "run", "cli", "--", "git", "status"], {
stdout: () => {},
Expand Down
Loading