mirror of
https://github.com/jparkerweb/plan2code.git
synced 2026-11-16 20:45:33 -08:00
Add the git-commit skill and dashboard card, and the No changes button, as v2.6.0
AI Assisted
This commit is contained in:
1 parent
1877ca1fa7
commit
50a78a6917
37 files changed
+1001
-141
No files matched your search
@@ -13,7 +13,7 @@
|
||||
// The shots use the console's Ocean highlight rather than its default orange:
|
||||
// it is the console's nearest to the Plan2Code blue the site and README use.
|
||||
//
|
||||
// Shots: dashboard, question, doc, build, signoff, finish, ask.
|
||||
// Shots: dashboard, dashboard-utilities, question, doc, build, signoff, finish, ask.
|
||||
//
|
||||
// Needs puppeteer-core (`npm i --no-save puppeteer-core`, never added to
|
||||
// package.json) and a local Chrome or Edge. Writes nothing outside its temp
|
||||
@@ -53,6 +53,14 @@ const SHOTS = {
|
||||
scrollTo: ".dash-toggle",
|
||||
mustShow: ".dash-card:has(.pill.suggested)",
|
||||
},
|
||||
// The utility cards sit even lower: scroll until the Git commit card is the
|
||||
// last row in frame ("cmd:" picks a card by its command).
|
||||
"dashboard-utilities": {
|
||||
workflow: "dashboard",
|
||||
posts: ["dashboard"],
|
||||
scrollTo: "cmd:/plan2code-git-commit",
|
||||
mustShow: "cmd:/plan2code-git-commit",
|
||||
},
|
||||
question: { workflow: "plan", posts: ["question"] },
|
||||
doc: { workflow: "plan", posts: ["doc"], tab: "What we've agreed" },
|
||||
build: { workflow: "implement", posts: ["build"], tab: "Phase 3 tasks" },
|
||||
@@ -201,11 +209,15 @@ async function openTab(page, label) {
|
||||
async function scrollTo(page, { scrollTo: top, mustShow }) {
|
||||
const problem = await page.evaluate(
|
||||
(topSel, showSel) => {
|
||||
const node = document.querySelector(topSel);
|
||||
const find = (sel) =>
|
||||
sel.startsWith("cmd:")
|
||||
? [...document.querySelectorAll(".dash-card")].find((c) => c.querySelector(".dash-card-cmd")?.textContent.trim() === sel.slice(4))
|
||||
: document.querySelector(sel);
|
||||
const node = find(topSel);
|
||||
if (!node) return `nothing matched ${topSel}, captured from the top`;
|
||||
node.scrollIntoView({ block: "start", behavior: "instant" });
|
||||
node.scrollIntoView({ block: topSel.startsWith("cmd:") ? "end" : "start", behavior: "instant" });
|
||||
if (!showSel) return null;
|
||||
const show = document.querySelector(showSel);
|
||||
const show = find(showSel);
|
||||
if (!show) return `nothing matched ${showSel}`;
|
||||
const r = show.getBoundingClientRect();
|
||||
return r.top >= 0 && r.bottom <= window.innerHeight ? null : `${showSel} is not wholly in view`;
|
||||
@@ -329,7 +341,7 @@ async function main() {
|
||||
// A saved role keeps the dashboard's "pick your role" banner out of shot,
|
||||
// and the Ocean highlight is the console's nearest to the Plan2Code blue
|
||||
// the landing page uses.
|
||||
fs.writeFileSync(path.join(HOME, "looks.json"), JSON.stringify({ looks: { role: "engineer", accent: "ocean" } }));
|
||||
fs.writeFileSync(path.join(HOME, "looks.json"), JSON.stringify({ looks: { role: "engineer", accent: "ocean", welcomeSeen: true } }));
|
||||
browser = await puppeteer.launch({
|
||||
executablePath: browserPath,
|
||||
headless: true,
|
||||
|
||||
@@ -0,0 +1,299 @@
|
||||
// Tests for plan2code-git-commit's scripts/git-state.mjs.
|
||||
//
|
||||
// See skill-script-helpers.mjs for how these run.
|
||||
|
||||
import { test } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { execFileSync } from "node:child_process";
|
||||
import { runScript, tmp, write, gitInit } from "./skill-script-helpers.mjs";
|
||||
|
||||
const S = (cwd, ...a) => runScript("plan2code-git-commit", "git-state.mjs", a, { cwd });
|
||||
|
||||
// A repo with one commit on `branch`, and its git runner.
|
||||
function repoWithCommit(name, branch = "main") {
|
||||
const repo = tmp(name);
|
||||
const g = gitInit(repo, branch);
|
||||
write(repo, "a.txt", "a\n");
|
||||
g("add", "-A");
|
||||
g("commit", "-q", "-m", "init");
|
||||
return { repo, g };
|
||||
}
|
||||
|
||||
function bareRemote() {
|
||||
const bare = tmp("origin");
|
||||
execFileSync("git", ["init", "-q", "--bare", "-b", "main", bare], { stdio: "pipe" });
|
||||
return bare;
|
||||
}
|
||||
|
||||
/* ============================================================ git-state.mjs state */
|
||||
|
||||
test("git-state state: a clean repo with one commit and no remote", () => {
|
||||
const { repo } = repoWithCommit("gs-clean");
|
||||
const r = S(repo, "state");
|
||||
assert.equal(r.code, 0, r.stderr);
|
||||
assert.equal(r.json.branch, "main");
|
||||
assert.equal(r.json.detached, false);
|
||||
assert.equal(r.json.hasCommits, true);
|
||||
assert.equal(r.json.nothingToCommit, true);
|
||||
assert.deepEqual([r.json.staged, r.json.unstaged, r.json.untracked, r.json.conflicted], [[], [], [], []]);
|
||||
assert.deepEqual(r.json.remotes, []);
|
||||
assert.equal(r.json.upstream, null);
|
||||
assert.equal(r.json.push, null, "no remote, nothing to push");
|
||||
assert.equal(r.json.inProgress, null);
|
||||
});
|
||||
|
||||
test("git-state state: staged, unstaged, untracked and renamed files land in the right lists", () => {
|
||||
const { repo, g } = repoWithCommit("gs-files");
|
||||
write(repo, "b.txt", "b\n");
|
||||
write(repo, "c.txt", "c\n");
|
||||
g("add", "-A");
|
||||
g("commit", "-q", "-m", "more");
|
||||
write(repo, "a.txt", "changed\n"); // unstaged
|
||||
write(repo, "b.txt", "changed\n"); // staged...
|
||||
g("add", "b.txt");
|
||||
write(repo, "b.txt", "changed again\n"); // ...and unstaged too
|
||||
g("mv", "c.txt", "d.txt"); // staged rename
|
||||
write(repo, "u.txt", "new\n"); // untracked
|
||||
const r = S(repo, "state");
|
||||
assert.equal(r.code, 0, r.stderr);
|
||||
assert.deepEqual(r.json.staged, [
|
||||
{ path: "b.txt", status: "M" },
|
||||
{ path: "d.txt", status: "R" },
|
||||
]);
|
||||
assert.deepEqual(r.json.unstaged, [
|
||||
{ path: "a.txt", status: "M" },
|
||||
{ path: "b.txt", status: "M" },
|
||||
]);
|
||||
assert.deepEqual(r.json.untracked, [{ path: "u.txt", status: "?" }]);
|
||||
assert.ok(![...r.json.staged, ...r.json.unstaged].some((f) => f.path === "c.txt"), "a rename's old path is skipped");
|
||||
assert.equal(r.json.nothingToCommit, false);
|
||||
});
|
||||
|
||||
test("git-state state: the default branch from origin/HEAD, local main, local master, unborn, or none", () => {
|
||||
// origin/HEAD
|
||||
const bare = bareRemote();
|
||||
const { repo, g } = repoWithCommit("gs-def-origin");
|
||||
g("remote", "add", "origin", bare);
|
||||
g("push", "-q", "-u", "origin", "main");
|
||||
g("remote", "set-head", "origin", "-a");
|
||||
const fromOrigin = S(repo, "state").json;
|
||||
assert.equal(fromOrigin.defaultFrom, "origin/HEAD");
|
||||
assert.equal(fromOrigin.defaultBranch, "main");
|
||||
assert.equal(fromOrigin.onDefault, true);
|
||||
|
||||
// local main, and off the default
|
||||
const main = repoWithCommit("gs-def-main");
|
||||
assert.equal(S(main.repo, "state").json.defaultFrom, "local-main");
|
||||
main.g("checkout", "-q", "-b", "feature/x");
|
||||
const off = S(main.repo, "state").json;
|
||||
assert.equal(off.defaultBranch, "main");
|
||||
assert.equal(off.onDefault, false);
|
||||
|
||||
// local master
|
||||
const master = S(repoWithCommit("gs-def-master", "master").repo, "state").json;
|
||||
assert.equal(master.defaultFrom, "local-master");
|
||||
assert.equal(master.defaultBranch, "master");
|
||||
assert.equal(master.onDefault, true);
|
||||
|
||||
// no commits yet, on main
|
||||
const fresh = tmp("gs-def-unborn");
|
||||
gitInit(fresh, "main");
|
||||
const unborn = S(fresh, "state").json;
|
||||
assert.equal(unborn.hasCommits, false);
|
||||
assert.equal(unborn.branch, "main");
|
||||
assert.equal(unborn.defaultFrom, "unborn");
|
||||
assert.equal(unborn.defaultBranch, "main");
|
||||
assert.equal(unborn.onDefault, true);
|
||||
assert.equal(unborn.push, null, "no commits, nothing to push");
|
||||
|
||||
// neither main nor master: no default, so no branch offer
|
||||
const dev = S(repoWithCommit("gs-def-none", "develop").repo, "state").json;
|
||||
assert.equal(dev.defaultBranch, null);
|
||||
assert.equal(dev.defaultFrom, null);
|
||||
assert.equal(dev.onDefault, false);
|
||||
const devFresh = tmp("gs-def-none2");
|
||||
gitInit(devFresh, "develop");
|
||||
assert.equal(S(devFresh, "state").json.defaultBranch, null);
|
||||
});
|
||||
|
||||
test("git-state state: a detached HEAD has no branch and nothing to push", () => {
|
||||
const { repo, g } = repoWithCommit("gs-detached");
|
||||
g("remote", "add", "origin", bareRemote());
|
||||
g("checkout", "-q", "--detach");
|
||||
const r = S(repo, "state").json;
|
||||
assert.equal(r.detached, true);
|
||||
assert.equal(r.branch, null);
|
||||
assert.equal(r.onDefault, false);
|
||||
assert.equal(r.unpublished, false);
|
||||
assert.equal(r.push, null);
|
||||
});
|
||||
|
||||
test("git-state state: the push command for an unpublished branch, one remote or several", () => {
|
||||
const { repo, g } = repoWithCommit("gs-unpub", "feature/x");
|
||||
g("remote", "add", "origin", bareRemote());
|
||||
const one = S(repo, "state").json;
|
||||
assert.equal(one.unpublished, true);
|
||||
assert.equal(one.upstream, null);
|
||||
assert.equal(one.ahead, null);
|
||||
assert.deepEqual(one.push, { command: "git push -u origin feature/x", setsUpstream: true, remote: "origin", needsRemoteChoice: false });
|
||||
|
||||
g("remote", "add", "backup", bareRemote());
|
||||
const two = S(repo, "state").json;
|
||||
assert.equal(two.push.remote, "origin", "origin wins when there are several");
|
||||
assert.equal(two.push.needsRemoteChoice, true);
|
||||
assert.equal(two.push.command, "git push -u origin feature/x");
|
||||
|
||||
g("remote", "remove", "origin");
|
||||
g("remote", "add", "zeta", bareRemote());
|
||||
const noOrigin = S(repo, "state").json;
|
||||
assert.equal(noOrigin.push.remote, "backup", "no origin: the first remote");
|
||||
assert.equal(noOrigin.push.needsRemoteChoice, true);
|
||||
});
|
||||
|
||||
test("git-state state: ahead of an upstream is a plain git push, pushed is null", () => {
|
||||
const { repo, g } = repoWithCommit("gs-ahead");
|
||||
g("remote", "add", "origin", bareRemote());
|
||||
g("push", "-q", "-u", "origin", "main");
|
||||
const synced = S(repo, "state").json;
|
||||
assert.equal(synced.upstream, "origin/main");
|
||||
assert.equal(synced.ahead, 0);
|
||||
assert.equal(synced.behind, 0);
|
||||
assert.equal(synced.unpublished, false);
|
||||
assert.equal(synced.push, null);
|
||||
|
||||
write(repo, "n.txt", "n\n");
|
||||
g("add", "-A");
|
||||
g("commit", "-q", "-m", "next");
|
||||
const ahead = S(repo, "state").json;
|
||||
assert.equal(ahead.ahead, 1);
|
||||
assert.equal(ahead.behind, 0);
|
||||
assert.deepEqual(ahead.push, { command: "git push", setsUpstream: false, remote: "origin", needsRemoteChoice: false });
|
||||
});
|
||||
|
||||
test("git-state state: a merge in progress and its conflicted files", () => {
|
||||
const repo = tmp("gs-merge");
|
||||
const g = gitInit(repo, "main");
|
||||
write(repo, "f.txt", "a\n");
|
||||
g("add", "-A");
|
||||
g("commit", "-q", "-m", "base");
|
||||
g("checkout", "-q", "-b", "x");
|
||||
write(repo, "f.txt", "b\n");
|
||||
g("commit", "-q", "-am", "x side");
|
||||
g("checkout", "-q", "main");
|
||||
write(repo, "f.txt", "c\n");
|
||||
g("commit", "-q", "-am", "main side");
|
||||
assert.throws(() => g("merge", "x"));
|
||||
const r = S(repo, "state").json;
|
||||
assert.equal(r.inProgress, "merge");
|
||||
assert.deepEqual(r.conflicted, [{ path: "f.txt", status: "UU" }]);
|
||||
assert.ok(!r.staged.some((f) => f.path === "f.txt") && !r.unstaged.some((f) => f.path === "f.txt"), "listed only under conflicted");
|
||||
assert.equal(r.nothingToCommit, false);
|
||||
});
|
||||
|
||||
test("git-state state: secrets are flagged, examples are not, and large files are listed", () => {
|
||||
const { repo } = repoWithCommit("gs-risky");
|
||||
for (const f of [".env", ".env.local", "id_rsa", "id_ed25519.pub", "server.pem", "secrets.json", "credentials.json", ".npmrc", "config/.env"]) write(repo, f, "x\n");
|
||||
for (const f of [".env.example", ".env.sample", "key.txt", "notes.md"]) write(repo, f, "x\n");
|
||||
write(repo, "video.bin", Buffer.alloc(6 * 1024 * 1024, 1));
|
||||
write(repo, "small.bin", Buffer.alloc(1024 * 1024, 1));
|
||||
const r = S(repo, "state").json;
|
||||
assert.deepEqual(r.sensitive, [".env", ".env.local", ".npmrc", "config/.env", "credentials.json", "id_ed25519.pub", "id_rsa", "secrets.json", "server.pem"]);
|
||||
assert.deepEqual(r.large, [{ path: "video.bin", bytes: 6 * 1024 * 1024 }]);
|
||||
});
|
||||
|
||||
test("git-state state: reading leaves the index untouched", () => {
|
||||
const { repo } = repoWithCommit("gs-readonly");
|
||||
const index = path.join(repo, ".git", "index");
|
||||
// Same content, new mtime: a plain git status would refresh and rewrite the index.
|
||||
const later = new Date(Date.now() + 5000);
|
||||
fs.utimesSync(path.join(repo, "a.txt"), later, later);
|
||||
const before = fs.readFileSync(index);
|
||||
assert.equal(S(repo, "state").code, 0);
|
||||
assert.ok(before.equals(fs.readFileSync(index)), "the index file is byte-for-byte the same");
|
||||
});
|
||||
|
||||
test("git-state: outside a repository, and a bad subcommand", () => {
|
||||
const plain = tmp("gs-norepo");
|
||||
const r = S(plain, "state");
|
||||
assert.equal(r.code, 3);
|
||||
assert.equal(r.json.error, "not-a-repo");
|
||||
assert.match(r.json.next, /init-check/);
|
||||
assert.equal(S(plain, "branch-check", "--name", "x").code, 3);
|
||||
assert.equal(S(plain).code, 2);
|
||||
assert.equal(S(plain, "commit").code, 2);
|
||||
assert.equal(S(plain, "state", "extra").code, 2);
|
||||
});
|
||||
|
||||
/* ======================================================= git-state.mjs branch-check */
|
||||
|
||||
test("git-state branch-check: valid, invalid, taken and clashing names", () => {
|
||||
const { repo, g } = repoWithCommit("gs-branch");
|
||||
g("branch", "feat");
|
||||
const ok = S(repo, "branch-check", "--name", "feature/export-csv");
|
||||
assert.equal(ok.code, 0, ok.stderr);
|
||||
assert.deepEqual(ok.json, { ok: true, name: "feature/export-csv", valid: true, exists: false });
|
||||
for (const bad of ["bad..name", "has space", "-leading", "@{-1}", "ends/"]) {
|
||||
const r = S(repo, "branch-check", "--name", bad);
|
||||
assert.equal(r.code, 4, bad);
|
||||
assert.equal(r.json.error, "invalid-name", bad);
|
||||
}
|
||||
assert.match(S(repo, "branch-check", "--name", "bad..name").json.next, /feature\//);
|
||||
const taken = S(repo, "branch-check", "--name", "main");
|
||||
assert.equal(taken.code, 4);
|
||||
assert.equal(taken.json.error, "branch-exists");
|
||||
assert.match(taken.json.next, /main-2/);
|
||||
const clash = S(repo, "branch-check", "--name", "feat/x");
|
||||
assert.equal(clash.code, 4);
|
||||
assert.equal(clash.json.error, "branch-conflict");
|
||||
assert.equal(S(repo, "branch-check").code, 2);
|
||||
});
|
||||
|
||||
/* ========================================================= git-state.mjs init-check */
|
||||
|
||||
test("git-state init-check: a plain folder is safe and suggests what to ignore", () => {
|
||||
const dir = tmp("gs-init");
|
||||
for (const f of ["node_modules/x/index.js", "dist/out.js", ".env", ".env.example", "app.log", "src/a.js"]) write(dir, f, "x\n");
|
||||
const r = S(dir, "init-check");
|
||||
assert.equal(r.code, 0, r.stderr);
|
||||
assert.equal(r.json.safe, true);
|
||||
assert.equal(r.json.reason, undefined);
|
||||
assert.equal(r.json.insideRepo, false);
|
||||
assert.equal(r.json.hasGitignore, false);
|
||||
assert.deepEqual(r.json.suggestedIgnore, ["node_modules/", "dist/", ".env", ".env.*", "!.env.example", "*.log"]);
|
||||
write(dir, ".gitignore", "x\n");
|
||||
assert.equal(S(dir, "init-check").json.hasGitignore, true);
|
||||
const empty = tmp("gs-init-empty");
|
||||
assert.deepEqual(S(empty, "init-check").json.suggestedIgnore, []);
|
||||
});
|
||||
|
||||
test("git-state init-check: inside a repository, the home folder, and a drive root are not safe", () => {
|
||||
const { repo } = repoWithCommit("gs-init-repo");
|
||||
write(repo, "sub/x.txt", "x\n");
|
||||
const inside = S(path.join(repo, "sub"), "init-check").json;
|
||||
assert.equal(inside.safe, false);
|
||||
assert.equal(inside.reason, "inside-repo");
|
||||
assert.equal(inside.insideRepo, true);
|
||||
assert.equal(path.resolve(inside.repoRoot).toLowerCase(), repo.toLowerCase());
|
||||
|
||||
const home = tmp("gs-init-home");
|
||||
const asHome = runScript("plan2code-git-commit", "git-state.mjs", ["init-check"], { cwd: home, env: { HOME: home, USERPROFILE: home } });
|
||||
assert.equal(asHome.json.safe, false);
|
||||
assert.equal(asHome.json.reason, "home");
|
||||
|
||||
const root = path.parse(process.cwd()).root;
|
||||
const atRoot = S(root, "init-check").json;
|
||||
if (!atRoot.insideRepo) {
|
||||
assert.equal(atRoot.safe, false);
|
||||
assert.equal(atRoot.reason, "root");
|
||||
}
|
||||
});
|
||||
|
||||
/* ============================================================ the skill's other script */
|
||||
|
||||
test("plan2code-git-commit ships commit-msg.mjs with the two -m flags", () => {
|
||||
const r = runScript("plan2code-git-commit", "commit-msg.mjs", ["--subject", "Add the export", "--files", "src/a.js"]);
|
||||
assert.equal(r.code, 0, r.stderr);
|
||||
assert.equal(r.json.command, 'git add -- src/a.js && git commit -m "Add the export" -m "AI Assisted"');
|
||||
});
|
||||
@@ -228,7 +228,7 @@ test("specs archive: dry-run, move, refuse to clobber", () => {
|
||||
|
||||
/* ============================================================ commit-msg.mjs */
|
||||
|
||||
test("commit-msg: ticket from the branch, the three -m flags, subject rules", () => {
|
||||
test("commit-msg: the two -m flags on any branch, subject rules", () => {
|
||||
const repo = tmp("commit");
|
||||
const g = gitInit(repo, "feature/ABC-10968-export-csv");
|
||||
write(repo, "a.txt", "a");
|
||||
@@ -237,24 +237,29 @@ test("commit-msg: ticket from the branch, the three -m flags, subject rules", ()
|
||||
const C = (...a) => runScript("plan2code-review", "commit-msg.mjs", a, { cwd: repo });
|
||||
const ok = C("--subject", "Add the export endpoint", "--add-all");
|
||||
assert.equal(ok.code, 0, ok.stderr);
|
||||
assert.equal(ok.json.ticket, "ABC-10968");
|
||||
assert.equal(ok.json.command, 'git add -A && git commit -m "Add the export endpoint" -m "ABC-10968" -m "AI Assisted"');
|
||||
assert.equal(ok.json.message, "Add the export endpoint\n\nABC-10968\nAI Assisted");
|
||||
assert.equal(ok.json.ticket, undefined);
|
||||
assert.equal(ok.json.branch, undefined);
|
||||
assert.equal(ok.json.command, 'git add -A && git commit -m "Add the export endpoint" -m "AI Assisted"');
|
||||
assert.equal(ok.json.message, "Add the export endpoint\n\nAI Assisted");
|
||||
assert.equal(C("--subject", "x".repeat(101)).code, 4);
|
||||
assert.equal(C("--subject", 'say "hi"').code, 4);
|
||||
assert.equal(C("--subject", "costs $5").code, 4);
|
||||
assert.equal(C().code, 2);
|
||||
assert.match(C("--subject", "Fix it", "--files", "src/a.ts", "--files", "my file.md").json.command, /^git add -- src\/a\.ts 'my file\.md' && git commit/);
|
||||
g("checkout", "-q", "-b", "chore/no-ticket-here");
|
||||
const none = C("--subject", "Fix it");
|
||||
assert.equal(none.code, 4);
|
||||
assert.equal(none.json.error, "no-ticket");
|
||||
assert.equal(C("--subject", "Fix it", "--ticket", "ABC-1").json.ticket, "ABC-1");
|
||||
assert.equal(C("--subject", "Fix it", "--ticket", "abc-1").code, 4);
|
||||
g("checkout", "-q", "-b", "PROJ2-7_underscore");
|
||||
assert.equal(C("--subject", "Fix it").json.ticket, "PROJ2-7");
|
||||
const fix = 'git commit -m "Fix it" -m "AI Assisted"';
|
||||
assert.equal(C("--subject", "Fix it").json.commit, fix, "ticket branch");
|
||||
g("checkout", "-q", "-b", "main");
|
||||
const onMain = C("--subject", "Fix it");
|
||||
assert.equal(onMain.json.commit, fix, "main");
|
||||
assert.equal(onMain.json.message, "Fix it\n\nAI Assisted");
|
||||
assert.equal(onMain.json.ticket, undefined);
|
||||
assert.equal(onMain.json.branch, undefined);
|
||||
const flag = C("--subject", "Fix it", "--ticket", "ABC-1");
|
||||
assert.equal(flag.code, 2, "--ticket is an unknown flag");
|
||||
assert.equal(flag.json.error, "unknown-flag");
|
||||
const notRepo = runScript("plan2code-review", "commit-msg.mjs", ["--subject", "x"], { cwd: tmp("norepo") });
|
||||
assert.equal(notRepo.code, 3);
|
||||
assert.equal(notRepo.code, 0, "no repository needed");
|
||||
assert.equal(notRepo.json.commit, 'git commit -m "x" -m "AI Assisted"');
|
||||
});
|
||||
|
||||
/* ============================================================ agent-files.mjs */
|
||||
@@ -427,7 +432,7 @@ test("commit-msg: a repo with no commits, stray arguments, and paths quoted for
|
||||
const repo = tmp("commit2");
|
||||
gitInit(repo, "feature/ABC-12-x");
|
||||
const C = (...a) => runScript("plan2code-review", "commit-msg.mjs", a, { cwd: repo });
|
||||
assert.equal(C("--subject", "Add x").json.ticket, "ABC-12", "no commits yet");
|
||||
assert.equal(C("--subject", "Add x").json.commit, 'git commit -m "Add x" -m "AI Assisted"', "no commits yet");
|
||||
const stray = C("--subject", "Fix", "--files", "a.js", "b.js");
|
||||
assert.equal(stray.code, 2);
|
||||
assert.equal(stray.json.error, "stray-argument");
|
||||
@@ -577,7 +582,7 @@ test("commit-msg: @ and - paths are quoted, git add ends its options, risky subj
|
||||
const files = C("--subject", "Fix", "--files", "@types/x.d.ts", "--files", "-weird.md", "--files", "src/a@b.js");
|
||||
assert.equal(files.code, 0, files.stderr);
|
||||
assert.equal(files.json.add, "git add -- '@types/x.d.ts' '-weird.md' src/a@b.js");
|
||||
assert.equal(files.json.commit, 'git commit -m "Fix" -m "ABC-12" -m "AI Assisted"');
|
||||
assert.equal(files.json.commit, 'git commit -m "Fix" -m "AI Assisted"');
|
||||
assert.equal(files.json.command, `${files.json.add} && ${files.json.commit}`);
|
||||
assert.equal(C("--subject", "Fix", "--add-all").json.add, "git add -A");
|
||||
const bare = C("--subject", "Fix").json;
|
||||
|
||||
@@ -52,6 +52,7 @@ import {
|
||||
DONE_REPLY,
|
||||
finishPaused,
|
||||
fitWithin,
|
||||
GIT_INIT_NOTE,
|
||||
handoffShape,
|
||||
handoffText,
|
||||
HOME_REPLY,
|
||||
@@ -185,6 +186,7 @@ import {
|
||||
cwdHash,
|
||||
handOff,
|
||||
initialWorkspace,
|
||||
insideGitRepo,
|
||||
latestOpenCaps,
|
||||
parseArgs,
|
||||
pendingWorkspaceChanges,
|
||||
@@ -3030,6 +3032,63 @@ test("the project scan reads each spec's pipeline stage off its files", () => {
|
||||
}
|
||||
});
|
||||
|
||||
// The dashboard's Git commit card offers to start a repository when the folder
|
||||
// is not one. The scan answers that from the filesystem, never from a git
|
||||
// process, and a linked worktree (a .git file, not a folder) must count.
|
||||
test("scanProject reports isGit for a repo, a subfolder, a linked worktree and a plain folder", () => {
|
||||
const saved = {};
|
||||
for (const k of ["GIT_DIR", "GIT_WORK_TREE", "GIT_COMMON_DIR"]) {
|
||||
saved[k] = process.env[k];
|
||||
delete process.env[k];
|
||||
}
|
||||
const base = fs.mkdtempSync(path.join(os.tmpdir(), "p2c-isgit-"));
|
||||
try {
|
||||
const repo = path.join(base, "repo");
|
||||
fs.mkdirSync(path.join(repo, "sub"), { recursive: true });
|
||||
const git = (cwd, ...a) => execFileSync("git", a, { cwd, encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] }).trim();
|
||||
git(repo, "init", "-q");
|
||||
git(repo, "-c", "user.email=t@t", "-c", "user.name=t", "commit", "-q", "--allow-empty", "-m", "x");
|
||||
git(repo, "worktree", "add", "-q", path.join(base, "wt"));
|
||||
const plain = path.join(base, "plain");
|
||||
fs.mkdirSync(plain);
|
||||
|
||||
assert.equal(scanProject(repo).isGit, true);
|
||||
assert.equal(scanProject(path.join(repo, "sub")).isGit, true);
|
||||
assert.equal(fs.statSync(path.join(base, "wt", ".git")).isFile(), true, "a linked worktree's .git is a file");
|
||||
assert.equal(scanProject(path.join(base, "wt")).isGit, true);
|
||||
assert.equal(scanProject(plain).isGit, false);
|
||||
assert.equal(insideGitRepo(plain), false);
|
||||
|
||||
// When git is steered by the environment, git decides: count it as a repo.
|
||||
process.env.GIT_DIR = path.join(plain, "nowhere");
|
||||
assert.equal(insideGitRepo(plain), true);
|
||||
} finally {
|
||||
for (const [k, v] of Object.entries(saved)) {
|
||||
if (v === undefined) delete process.env[k];
|
||||
else process.env[k] = v;
|
||||
}
|
||||
fs.rmSync(base, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test("the Git commit card stays clickable outside a repository and says what happens", () => {
|
||||
const entry = SKILL_CATALOG.find((e) => e.skill === "plan2code-git-commit");
|
||||
const outside = cardAvailability(entry, { hasAgents: true, isGit: false }, null);
|
||||
assert.equal(outside.on, true);
|
||||
assert.equal(outside.note, GIT_INIT_NOTE);
|
||||
for (const scan of [{ hasAgents: true, isGit: true }, { hasAgents: true }, null]) {
|
||||
const a = cardAvailability(entry, scan, null);
|
||||
assert.equal(a.on, true);
|
||||
assert.equal(a.note, undefined);
|
||||
}
|
||||
const scan = { hasAgents: true, isGit: false, specs: [] };
|
||||
assert.equal(cardPresentation(entry, scan, null).detail, GIT_INIT_NOTE);
|
||||
// The agent's own detail line still wins over the note.
|
||||
const withSpec = { hasAgents: true, isGit: false, specs: [{ dir: "specs/x", name: "x", state: "building" }] };
|
||||
const menu = { details: { "plan2code-git-commit": "Two changes ready" } };
|
||||
assert.equal(cardPresentation(entry, withSpec, withSpec.specs[0], menu).detail, "Two changes ready");
|
||||
});
|
||||
|
||||
test("a verdict's button text never renders blank", () => {
|
||||
assert.equal(verdictText({ id: "approve", label: "Approve it" }), "Approve it");
|
||||
assert.equal(verdictText({ id: "approve", text: "Approve it" }), "Approve it");
|
||||
|
||||
Reference in new issue
Block a user