mirror of
https://github.com/merlinhu1/truthmark.git
synced 2026-08-25 07:53:25 +02:00
167 lines
5.8 KiB
TypeScript
167 lines
5.8 KiB
TypeScript
import fs from "node:fs/promises";
|
|
|
|
import { describe, expect, it } from "vitest";
|
|
|
|
import { runConfig } from "../../src/config/command.js";
|
|
import { runInit } from "../../src/init/init.js";
|
|
|
|
import { createTempRepo } from "../helpers/temp-repo.js";
|
|
|
|
describe("runInit instruction integration", () => {
|
|
it("installs a single managed AGENTS block with agent-native workflow guidance", async () => {
|
|
const repo = await createTempRepo();
|
|
|
|
try {
|
|
await runConfig(repo.rootDir, {});
|
|
await runInit(repo.rootDir);
|
|
|
|
const agents = await repo.readFile("AGENTS.md");
|
|
|
|
expect(agents.match(/<!-- truthmark:start -->/g)).toHaveLength(1);
|
|
expect(agents.match(/<!-- truthmark:end -->/g)).toHaveLength(1);
|
|
expect(agents.split("\n").length).toBeLessThanOrEqual(20);
|
|
expect(agents.slice(0, 220)).toContain("Truthmark Workflow");
|
|
expect(agents).not.toContain("/skill truthmark-sync");
|
|
expect(agents).not.toContain("OpenCode /skill truthmark-sync");
|
|
expect(agents).toContain("Truthmark-managed block");
|
|
expect(agents).not.toContain("Generated by Truthmark");
|
|
expect(agents).toContain("After functional code changes");
|
|
expect(agents).toContain("code changed -> tests -> Sync -> report");
|
|
expect(agents).toContain("Delegation is host-owned");
|
|
expect(agents).toContain(
|
|
"Explicit workflows: Truth Structure, Truth Document, Truth Realize, Truth Check",
|
|
);
|
|
expect(agents).toContain("load the installed skill for details");
|
|
expect(agents).not.toContain("/skill truthmark-structure");
|
|
expect(agents).not.toContain("/skill truthmark-check");
|
|
expect(agents).not.toContain(
|
|
"truthmark check --json --workflow truth-sync",
|
|
);
|
|
expect(agents).not.toContain("Truth Structure: completed");
|
|
expect(agents).not.toContain("Truth Sync: completed");
|
|
expect(agents).not.toContain("Truth Sync: skipped");
|
|
expect(agents).not.toContain("Truth Realize: completed");
|
|
expect(agents).not.toContain("### Truth Check");
|
|
expect(agents).toContain("inspect checkout directly");
|
|
expect(agents).not.toContain("truthmark packet --changed");
|
|
|
|
await expect(fs.stat(`${repo.rootDir}/OPENCODE.md`)).rejects.toThrow();
|
|
} finally {
|
|
await repo.cleanup();
|
|
}
|
|
});
|
|
|
|
it("rerenders the managed block without duplicating it and leaves subagent choice to the host", async () => {
|
|
const repo = await createTempRepo();
|
|
|
|
try {
|
|
await runConfig(repo.rootDir, {});
|
|
await runInit(repo.rootDir);
|
|
await repo.writeFile(
|
|
".truthmark/config.yml",
|
|
`version: 1
|
|
authority:
|
|
- docs/truthmark/routes/areas.md
|
|
- docs/truthmark/routes/areas/**/*.md
|
|
instruction_targets:
|
|
- AGENTS.md
|
|
frontmatter:
|
|
required: []
|
|
recommended:
|
|
- status
|
|
ignore: []
|
|
`,
|
|
);
|
|
|
|
await runInit(repo.rootDir);
|
|
|
|
const agents = await repo.readFile("AGENTS.md");
|
|
|
|
expect(agents.match(/<!-- truthmark:start -->/g)).toHaveLength(1);
|
|
expect(agents).toContain("Delegation is host-owned");
|
|
expect(agents).not.toContain(".truthmark/local.yml");
|
|
expect(agents).not.toContain("truth_sync.sync_agent");
|
|
expect(agents).toContain(
|
|
"later functional changes need a fresh Sync review",
|
|
);
|
|
expect(agents).not.toContain("Explicit invocation:");
|
|
} finally {
|
|
await repo.cleanup();
|
|
}
|
|
});
|
|
|
|
it("removes auto-removable retired generated surfaces but preserves stale Gemini surfaces", async () => {
|
|
const repo = await createTempRepo();
|
|
|
|
try {
|
|
await runConfig(repo.rootDir, {});
|
|
await runInit(repo.rootDir);
|
|
await repo.writeFile(
|
|
".agents/skills/truthmark-preview/SKILL.md",
|
|
"# Legacy Preview Skill\n",
|
|
);
|
|
await repo.writeFile(
|
|
".github/prompts/truthmark-preview.prompt.md",
|
|
"# Legacy Preview Prompt\n",
|
|
);
|
|
await repo.writeFile(
|
|
".gemini/commands/truthmark/preview.toml",
|
|
"description = \"Legacy Preview Command\"\n",
|
|
);
|
|
await repo.writeFile("GEMINI.md", "# Legacy Gemini instructions\n");
|
|
await repo.writeFile(
|
|
".gemini/skills/truthmark-sync/SKILL.md",
|
|
"# Legacy Gemini Sync Skill\n",
|
|
);
|
|
await repo.writeFile(
|
|
".gemini/agents/truth-doc-writer.md",
|
|
"# Legacy Gemini writer\n",
|
|
);
|
|
await repo.writeFile(
|
|
".gemini/commands/truthmark/sync.toml",
|
|
"description = \"Legacy Sync Command\"\n",
|
|
);
|
|
await repo.writeFile(
|
|
".agents/skills/truthmark-sync/helper-manifest.yml",
|
|
"id: truthmark-sync\n",
|
|
);
|
|
await repo.writeFile(
|
|
".opencode/skills/truthmark-sync/support/helper-policy.md",
|
|
"Legacy helper policy\n",
|
|
);
|
|
|
|
await runInit(repo.rootDir);
|
|
|
|
await expect(
|
|
fs.stat(`${repo.rootDir}/.agents/skills/truthmark-preview/SKILL.md`),
|
|
).rejects.toThrow();
|
|
await expect(
|
|
fs.stat(`${repo.rootDir}/.github/prompts/truthmark-preview.prompt.md`),
|
|
).rejects.toThrow();
|
|
await expect(
|
|
fs.stat(`${repo.rootDir}/.gemini/commands/truthmark/preview.toml`),
|
|
).resolves.toBeDefined();
|
|
await expect(fs.stat(`${repo.rootDir}/GEMINI.md`)).resolves.toBeDefined();
|
|
await expect(
|
|
fs.stat(`${repo.rootDir}/.gemini/skills/truthmark-sync/SKILL.md`),
|
|
).resolves.toBeDefined();
|
|
await expect(
|
|
fs.stat(`${repo.rootDir}/.gemini/agents/truth-doc-writer.md`),
|
|
).resolves.toBeDefined();
|
|
await expect(
|
|
fs.stat(`${repo.rootDir}/.gemini/commands/truthmark/sync.toml`),
|
|
).resolves.toBeDefined();
|
|
await expect(
|
|
fs.stat(`${repo.rootDir}/.agents/skills/truthmark-sync/helper-manifest.yml`),
|
|
).rejects.toThrow();
|
|
await expect(
|
|
fs.stat(
|
|
`${repo.rootDir}/.opencode/skills/truthmark-sync/support/helper-policy.md`,
|
|
),
|
|
).rejects.toThrow();
|
|
} finally {
|
|
await repo.cleanup();
|
|
}
|
|
});
|
|
});
|