oh-my-copilot 5.25.2 → 5.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +2 -2
- package/.claude-plugin/plugin.json +1 -1
- package/README.md +1 -0
- package/bridge/claude-md-coordinator.cjs +2 -2
- package/bridge/cli.cjs +9249 -4138
- package/bridge/mcp-server.cjs +4894 -1400
- package/bridge/runtime-cli.cjs +14 -9
- package/bridge/team-mcp.cjs +3 -2
- package/bridge/team.js +14 -9
- package/dist/cli/commands/factory-bench.d.ts +10 -0
- package/dist/cli/commands/factory-bench.d.ts.map +1 -0
- package/dist/cli/commands/factory-bench.js +122 -0
- package/dist/cli/commands/factory-bench.js.map +1 -0
- package/dist/cli/commands/factory-dashboard.d.ts +14 -0
- package/dist/cli/commands/factory-dashboard.d.ts.map +1 -0
- package/dist/cli/commands/factory-dashboard.js +51 -0
- package/dist/cli/commands/factory-dashboard.js.map +1 -0
- package/dist/cli/commands/factory.d.ts.map +1 -1
- package/dist/cli/commands/factory.js +10 -2
- package/dist/cli/commands/factory.js.map +1 -1
- package/dist/copilot-run/__tests__/job.fail-closed.test.d.ts +2 -0
- package/dist/copilot-run/__tests__/job.fail-closed.test.d.ts.map +1 -0
- package/dist/copilot-run/__tests__/job.fail-closed.test.js +64 -0
- package/dist/copilot-run/__tests__/job.fail-closed.test.js.map +1 -0
- package/dist/copilot-run/__tests__/job.large-tree.test.d.ts +2 -0
- package/dist/copilot-run/__tests__/job.large-tree.test.d.ts.map +1 -0
- package/dist/copilot-run/__tests__/job.large-tree.test.js +47 -0
- package/dist/copilot-run/__tests__/job.large-tree.test.js.map +1 -0
- package/dist/copilot-run/__tests__/sandbox.test.js +125 -1
- package/dist/copilot-run/__tests__/sandbox.test.js.map +1 -1
- package/dist/copilot-run/job.d.ts.map +1 -1
- package/dist/copilot-run/job.js +14 -3
- package/dist/copilot-run/job.js.map +1 -1
- package/dist/copilot-run/sandbox.d.ts +53 -0
- package/dist/copilot-run/sandbox.d.ts.map +1 -1
- package/dist/copilot-run/sandbox.js +176 -14
- package/dist/copilot-run/sandbox.js.map +1 -1
- package/dist/factory/bench/__tests__/bench.fake.test.d.ts +2 -0
- package/dist/factory/bench/__tests__/bench.fake.test.d.ts.map +1 -0
- package/dist/factory/bench/__tests__/bench.fake.test.js +87 -0
- package/dist/factory/bench/__tests__/bench.fake.test.js.map +1 -0
- package/dist/factory/bench/__tests__/bench.smoke.test.d.ts +2 -0
- package/dist/factory/bench/__tests__/bench.smoke.test.d.ts.map +1 -0
- package/dist/factory/bench/__tests__/bench.smoke.test.js +54 -0
- package/dist/factory/bench/__tests__/bench.smoke.test.js.map +1 -0
- package/dist/factory/bench/__tests__/bench.units.test.d.ts +2 -0
- package/dist/factory/bench/__tests__/bench.units.test.d.ts.map +1 -0
- package/dist/factory/bench/__tests__/bench.units.test.js +842 -0
- package/dist/factory/bench/__tests__/bench.units.test.js.map +1 -0
- package/dist/factory/bench/fake-lanes.d.ts +39 -0
- package/dist/factory/bench/fake-lanes.d.ts.map +1 -0
- package/dist/factory/bench/fake-lanes.js +127 -0
- package/dist/factory/bench/fake-lanes.js.map +1 -0
- package/dist/factory/bench/fixture.d.ts +55 -0
- package/dist/factory/bench/fixture.d.ts.map +1 -0
- package/dist/factory/bench/fixture.js +128 -0
- package/dist/factory/bench/fixture.js.map +1 -0
- package/dist/factory/bench/model-probe.d.ts +37 -0
- package/dist/factory/bench/model-probe.d.ts.map +1 -0
- package/dist/factory/bench/model-probe.js +148 -0
- package/dist/factory/bench/model-probe.js.map +1 -0
- package/dist/factory/bench/runner.d.ts +163 -0
- package/dist/factory/bench/runner.d.ts.map +1 -0
- package/dist/factory/bench/runner.js +687 -0
- package/dist/factory/bench/runner.js.map +1 -0
- package/dist/factory/bench/score.d.ts +211 -0
- package/dist/factory/bench/score.d.ts.map +1 -0
- package/dist/factory/bench/score.js +386 -0
- package/dist/factory/bench/score.js.map +1 -0
- package/dist/factory/bench/seed/issues.d.ts +51 -0
- package/dist/factory/bench/seed/issues.d.ts.map +1 -0
- package/dist/factory/bench/seed/issues.js +536 -0
- package/dist/factory/bench/seed/issues.js.map +1 -0
- package/dist/factory/bench/seed/project.d.ts +24 -0
- package/dist/factory/bench/seed/project.d.ts.map +1 -0
- package/dist/factory/bench/seed/project.js +216 -0
- package/dist/factory/bench/seed/project.js.map +1 -0
- package/dist/factory/check/__tests__/cli-local.test.js +17 -0
- package/dist/factory/check/__tests__/cli-local.test.js.map +1 -1
- package/dist/factory/check/cli.d.ts +14 -0
- package/dist/factory/check/cli.d.ts.map +1 -1
- package/dist/factory/check/cli.js +21 -0
- package/dist/factory/check/cli.js.map +1 -1
- package/dist/factory/dashboard/__tests__/dashboard.test.d.ts +2 -0
- package/dist/factory/dashboard/__tests__/dashboard.test.d.ts.map +1 -0
- package/dist/factory/dashboard/__tests__/dashboard.test.js +148 -0
- package/dist/factory/dashboard/__tests__/dashboard.test.js.map +1 -0
- package/dist/factory/dashboard/collect.d.ts +96 -0
- package/dist/factory/dashboard/collect.d.ts.map +1 -0
- package/dist/factory/dashboard/collect.js +234 -0
- package/dist/factory/dashboard/collect.js.map +1 -0
- package/dist/factory/dashboard/render.d.ts +11 -0
- package/dist/factory/dashboard/render.d.ts.map +1 -0
- package/dist/factory/dashboard/render.js +77 -0
- package/dist/factory/dashboard/render.js.map +1 -0
- package/dist/factory/poll.d.ts +2 -0
- package/dist/factory/poll.d.ts.map +1 -1
- package/dist/factory/poll.js +2 -2
- package/dist/factory/poll.js.map +1 -1
- package/dist/factory/run/__tests__/auto-merge-flaky.test.d.ts +2 -0
- package/dist/factory/run/__tests__/auto-merge-flaky.test.d.ts.map +1 -0
- package/dist/factory/run/__tests__/auto-merge-flaky.test.js +131 -0
- package/dist/factory/run/__tests__/auto-merge-flaky.test.js.map +1 -0
- package/dist/factory/run/__tests__/auto-merge.test.d.ts +2 -0
- package/dist/factory/run/__tests__/auto-merge.test.d.ts.map +1 -0
- package/dist/factory/run/__tests__/auto-merge.test.js +541 -0
- package/dist/factory/run/__tests__/auto-merge.test.js.map +1 -0
- package/dist/factory/run/__tests__/container-gate.test.d.ts +2 -0
- package/dist/factory/run/__tests__/container-gate.test.d.ts.map +1 -0
- package/dist/factory/run/__tests__/container-gate.test.js +733 -0
- package/dist/factory/run/__tests__/container-gate.test.js.map +1 -0
- package/dist/factory/run/__tests__/engine.auto-merge.github.test.d.ts +2 -0
- package/dist/factory/run/__tests__/engine.auto-merge.github.test.d.ts.map +1 -0
- package/dist/factory/run/__tests__/engine.auto-merge.github.test.js +142 -0
- package/dist/factory/run/__tests__/engine.auto-merge.github.test.js.map +1 -0
- package/dist/factory/run/__tests__/engine.gates-container.test.d.ts +2 -0
- package/dist/factory/run/__tests__/engine.gates-container.test.d.ts.map +1 -0
- package/dist/factory/run/__tests__/engine.gates-container.test.js +245 -0
- package/dist/factory/run/__tests__/engine.gates-container.test.js.map +1 -0
- package/dist/factory/run/__tests__/engine.gates-git-view-fail.test.d.ts +2 -0
- package/dist/factory/run/__tests__/engine.gates-git-view-fail.test.d.ts.map +1 -0
- package/dist/factory/run/__tests__/engine.gates-git-view-fail.test.js +71 -0
- package/dist/factory/run/__tests__/engine.gates-git-view-fail.test.js.map +1 -0
- package/dist/factory/run/__tests__/engine.gates-git-view.test.d.ts +2 -0
- package/dist/factory/run/__tests__/engine.gates-git-view.test.d.ts.map +1 -0
- package/dist/factory/run/__tests__/engine.gates-git-view.test.js +141 -0
- package/dist/factory/run/__tests__/engine.gates-git-view.test.js.map +1 -0
- package/dist/factory/run/__tests__/engine.gates-workspace.test.d.ts +2 -0
- package/dist/factory/run/__tests__/engine.gates-workspace.test.d.ts.map +1 -0
- package/dist/factory/run/__tests__/engine.gates-workspace.test.js +130 -0
- package/dist/factory/run/__tests__/engine.gates-workspace.test.js.map +1 -0
- package/dist/factory/run/__tests__/engine.human-review.test.js +4 -4
- package/dist/factory/run/__tests__/engine.human-review.test.js.map +1 -1
- package/dist/factory/run/__tests__/engine.local.auto-merge.test.d.ts +2 -0
- package/dist/factory/run/__tests__/engine.local.auto-merge.test.d.ts.map +1 -0
- package/dist/factory/run/__tests__/engine.local.auto-merge.test.js +196 -0
- package/dist/factory/run/__tests__/engine.local.auto-merge.test.js.map +1 -0
- package/dist/factory/run/__tests__/engine.private.test.js +17 -0
- package/dist/factory/run/__tests__/engine.private.test.js.map +1 -1
- package/dist/factory/run/__tests__/fake-lanes.d.ts +2 -0
- package/dist/factory/run/__tests__/fake-lanes.d.ts.map +1 -1
- package/dist/factory/run/__tests__/fake-lanes.js +6 -1
- package/dist/factory/run/__tests__/fake-lanes.js.map +1 -1
- package/dist/factory/run/__tests__/git-view.test.d.ts +2 -0
- package/dist/factory/run/__tests__/git-view.test.d.ts.map +1 -0
- package/dist/factory/run/__tests__/git-view.test.js +120 -0
- package/dist/factory/run/__tests__/git-view.test.js.map +1 -0
- package/dist/factory/run/__tests__/merge-policy.test.js +10 -0
- package/dist/factory/run/__tests__/merge-policy.test.js.map +1 -1
- package/dist/factory/run/__tests__/prepare-gates.gates-resume.test.js +2 -0
- package/dist/factory/run/__tests__/prepare-gates.gates-resume.test.js.map +1 -1
- package/dist/factory/run/__tests__/prepare-gates.moving-base.test.d.ts +2 -0
- package/dist/factory/run/__tests__/prepare-gates.moving-base.test.d.ts.map +1 -0
- package/dist/factory/run/__tests__/prepare-gates.moving-base.test.js +103 -0
- package/dist/factory/run/__tests__/prepare-gates.moving-base.test.js.map +1 -0
- package/dist/factory/run/__tests__/private-run.test.js +37 -1
- package/dist/factory/run/__tests__/private-run.test.js.map +1 -1
- package/dist/factory/run/__tests__/units.test.js +8 -1
- package/dist/factory/run/__tests__/units.test.js.map +1 -1
- package/dist/factory/run/__tests__/workspace-tree.test.d.ts +2 -0
- package/dist/factory/run/__tests__/workspace-tree.test.d.ts.map +1 -0
- package/dist/factory/run/__tests__/workspace-tree.test.js +325 -0
- package/dist/factory/run/__tests__/workspace-tree.test.js.map +1 -0
- package/dist/factory/run/auto-merge.d.ts +254 -0
- package/dist/factory/run/auto-merge.d.ts.map +1 -0
- package/dist/factory/run/auto-merge.js +785 -0
- package/dist/factory/run/auto-merge.js.map +1 -0
- package/dist/factory/run/budget.d.ts +14 -0
- package/dist/factory/run/budget.d.ts.map +1 -1
- package/dist/factory/run/budget.js +24 -0
- package/dist/factory/run/budget.js.map +1 -1
- package/dist/factory/run/clean.d.ts +3 -0
- package/dist/factory/run/clean.d.ts.map +1 -1
- package/dist/factory/run/clean.js +34 -0
- package/dist/factory/run/clean.js.map +1 -1
- package/dist/factory/run/container-gate.d.ts +230 -0
- package/dist/factory/run/container-gate.d.ts.map +1 -0
- package/dist/factory/run/container-gate.js +1076 -0
- package/dist/factory/run/container-gate.js.map +1 -0
- package/dist/factory/run/engine.d.ts +5 -1
- package/dist/factory/run/engine.d.ts.map +1 -1
- package/dist/factory/run/engine.js +582 -40
- package/dist/factory/run/engine.js.map +1 -1
- package/dist/factory/run/exec.d.ts +5 -0
- package/dist/factory/run/exec.d.ts.map +1 -1
- package/dist/factory/run/exec.js +17 -3
- package/dist/factory/run/exec.js.map +1 -1
- package/dist/factory/run/git-view.d.ts +39 -0
- package/dist/factory/run/git-view.d.ts.map +1 -0
- package/dist/factory/run/git-view.js +77 -0
- package/dist/factory/run/git-view.js.map +1 -0
- package/dist/factory/run/lane-commit.d.ts +2 -0
- package/dist/factory/run/lane-commit.d.ts.map +1 -1
- package/dist/factory/run/lane-commit.js +3 -1
- package/dist/factory/run/lane-commit.js.map +1 -1
- package/dist/factory/run/local-gate.d.ts +1 -0
- package/dist/factory/run/local-gate.d.ts.map +1 -1
- package/dist/factory/run/local-gate.js +2 -1
- package/dist/factory/run/local-gate.js.map +1 -1
- package/dist/factory/run/merge-policy.d.ts +24 -6
- package/dist/factory/run/merge-policy.d.ts.map +1 -1
- package/dist/factory/run/merge-policy.js +29 -7
- package/dist/factory/run/merge-policy.js.map +1 -1
- package/dist/factory/run/prepare.d.ts +27 -1
- package/dist/factory/run/prepare.d.ts.map +1 -1
- package/dist/factory/run/prepare.js +241 -28
- package/dist/factory/run/prepare.js.map +1 -1
- package/dist/factory/run/private-run.d.ts +7 -0
- package/dist/factory/run/private-run.d.ts.map +1 -1
- package/dist/factory/run/private-run.js +34 -3
- package/dist/factory/run/private-run.js.map +1 -1
- package/dist/factory/run/private-store.d.ts +2 -0
- package/dist/factory/run/private-store.d.ts.map +1 -1
- package/dist/factory/run/private-store.js +2 -1
- package/dist/factory/run/private-store.js.map +1 -1
- package/dist/factory/run/sandbox-exec.d.ts +22 -1
- package/dist/factory/run/sandbox-exec.d.ts.map +1 -1
- package/dist/factory/run/sandbox-exec.js +9 -0
- package/dist/factory/run/sandbox-exec.js.map +1 -1
- package/dist/factory/run/workspace-tree.d.ts +75 -0
- package/dist/factory/run/workspace-tree.d.ts.map +1 -0
- package/dist/factory/run/workspace-tree.js +299 -0
- package/dist/factory/run/workspace-tree.js.map +1 -0
- package/dist/forge/__tests__/gh-argv-baseline.factory.test.js +7 -5
- package/dist/forge/__tests__/gh-argv-baseline.factory.test.js.map +1 -1
- package/dist/forge/github/__tests__/required-checks.test.js +22 -1
- package/dist/forge/github/__tests__/required-checks.test.js.map +1 -1
- package/dist/forge/github/checks.d.ts +9 -0
- package/dist/forge/github/checks.d.ts.map +1 -1
- package/dist/forge/github/checks.js +26 -0
- package/dist/forge/github/checks.js.map +1 -1
- package/dist/forge/github/merge.d.ts +27 -0
- package/dist/forge/github/merge.d.ts.map +1 -1
- package/dist/forge/github/merge.js +44 -0
- package/dist/forge/github/merge.js.map +1 -1
- package/dist/forge/github/reviews.d.ts +2 -0
- package/dist/forge/github/reviews.d.ts.map +1 -1
- package/dist/forge/github/reviews.js.map +1 -1
- package/dist/smoke/copilot-factory-run-scenario.d.ts.map +1 -1
- package/dist/smoke/copilot-factory-run-scenario.js +4 -0
- package/dist/smoke/copilot-factory-run-scenario.js.map +1 -1
- package/dist/team/git-worktree.d.ts +8 -1
- package/dist/team/git-worktree.d.ts.map +1 -1
- package/dist/team/git-worktree.js +9 -2
- package/dist/team/git-worktree.js.map +1 -1
- package/dist/team/merge-coordinator.js +5 -5
- package/dist/team/merge-coordinator.js.map +1 -1
- package/dist/team/merge-orchestrator.d.ts.map +1 -1
- package/dist/team/merge-orchestrator.js +3 -1
- package/dist/team/merge-orchestrator.js.map +1 -1
- package/dist/team/runtime-v2.d.ts.map +1 -1
- package/dist/team/runtime-v2.js +2 -2
- package/dist/team/runtime-v2.js.map +1 -1
- package/docs/CLAUDE.md +1 -1
- package/docs/REFERENCE.md +133 -1
- package/package.json +2 -2
- package/plugin.json +1 -1
|
@@ -0,0 +1,541 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Opt-in auto-merge (auto-merge.ts): the user-config resolver, the tier
|
|
3
|
+
* classifier, every condition of the verdict, and the guard's one admitted
|
|
4
|
+
* GitHub merge shape. Pure: no git, no gh.
|
|
5
|
+
*/
|
|
6
|
+
import { describe, expect, it } from 'vitest';
|
|
7
|
+
import { githubAutoMergeArgs, githubCommitReadArgs, isGithubAutoMergeArgs } from '../../../forge/github/merge.js';
|
|
8
|
+
import { assertFactoryCommand, FactorySafetyError } from '../exec.js';
|
|
9
|
+
import { autoMergeComment, autoMergeVerdict, baseInstallFiles, baseTestSetup, hasFrontmatter, classifyChanges, committedMergeConfig, deniedPaths, isDocsPath, isFrontmatterCandidate, isTestPath, MANUAL_MERGE_LABEL, parseChangedEntries, patchLines, resolveAutoMergeConfig, } from '../auto-merge.js';
|
|
10
|
+
const HEAD = 'a'.repeat(40);
|
|
11
|
+
const OTHER = 'b'.repeat(40);
|
|
12
|
+
const URL = 'https://github.com/o/r';
|
|
13
|
+
const ROOT = process.platform === 'win32' ? 'C:\\work\\repo' : '/work/repo';
|
|
14
|
+
const userWith = (auto) => ({ factory: { merge: { auto } } });
|
|
15
|
+
const gh = { url: URL, root: ROOT, local: false };
|
|
16
|
+
const file = (path, added = 1, deleted = 0, mode = '100644') => ({ path, status: 'M', oldMode: mode, newMode: mode, added, deleted });
|
|
17
|
+
const gone = (path, deleted = 5) => ({ path, status: 'D', oldMode: '100644', newMode: '000000', added: 0, deleted });
|
|
18
|
+
const added = (path, lines = 5) => ({ path, status: 'A', oldMode: '000000', newMode: '100644', added: lines, deleted: 0 });
|
|
19
|
+
const all = { enabled: true, tiers: ['docs', 'tests', 'small'] };
|
|
20
|
+
describe('resolveAutoMergeConfig (user config only, per repository)', () => {
|
|
21
|
+
it('is off without an entry for this repository, and on with one', () => {
|
|
22
|
+
expect(resolveAutoMergeConfig(undefined, gh)).toEqual({});
|
|
23
|
+
expect(resolveAutoMergeConfig(userWith({ 'https://github.com/o/other': { enabled: true, tiers: ['docs'] } }), gh)).toEqual({});
|
|
24
|
+
expect(resolveAutoMergeConfig(userWith({ 'git@github.com:O/R.git': { enabled: true, tiers: ['docs'] } }), gh).config).toEqual({ enabled: true, tiers: ['docs'] });
|
|
25
|
+
expect(resolveAutoMergeConfig(userWith({ [URL]: { enabled: false, tiers: ['docs'] } }), gh)).toEqual({ key: URL });
|
|
26
|
+
});
|
|
27
|
+
it('the local forge keys by the repository root path; a path never matches a hosted repository', () => {
|
|
28
|
+
const local = { url: '/state/mirror.git', root: ROOT, local: true };
|
|
29
|
+
expect(resolveAutoMergeConfig(userWith({ [ROOT]: { enabled: true, tiers: ['small'], maxChangedLines: 5 } }), local).config).toEqual({ enabled: true, tiers: ['small'], maxChangedLines: 5 });
|
|
30
|
+
expect(resolveAutoMergeConfig(userWith({ [URL]: { enabled: true, tiers: ['small'] } }), local)).toEqual({});
|
|
31
|
+
expect(resolveAutoMergeConfig(userWith({ [ROOT]: { enabled: true, tiers: ['small'] } }), gh)).toEqual({});
|
|
32
|
+
});
|
|
33
|
+
it('a malformed value is an error and leaves auto-merge off', () => {
|
|
34
|
+
for (const bad of [
|
|
35
|
+
[],
|
|
36
|
+
{ [URL]: true },
|
|
37
|
+
{ [URL]: { enabled: 'yes', tiers: ['docs'] } },
|
|
38
|
+
{ [URL]: { enabled: true, tiers: [] } },
|
|
39
|
+
{ [URL]: { enabled: true, tiers: ['everything'] } },
|
|
40
|
+
{ [URL]: { enabled: true, tiers: ['docs'], maxChangedLines: 0 } },
|
|
41
|
+
{ [URL]: { enabled: true, tiers: ['docs'], maxFiles: 1.5 } },
|
|
42
|
+
{ [URL]: { enabled: true, tiers: ['docs'], allowProtected: true } },
|
|
43
|
+
{ [URL]: { enabled: true, tiers: ['docs'] }, 'https://github.com/O/R.git': { enabled: true, tiers: ['docs'] } },
|
|
44
|
+
]) {
|
|
45
|
+
const r = resolveAutoMergeConfig(userWith(bad), gh);
|
|
46
|
+
expect(r.error, JSON.stringify(bad)).toBeTruthy();
|
|
47
|
+
expect(r.config).toBeUndefined();
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
it('a committed factory.merge is detected so the engine can say it is ignored', () => {
|
|
51
|
+
expect(committedMergeConfig({ factory: { merge: { auto: {} } } })).toBe(true);
|
|
52
|
+
expect(committedMergeConfig({ factory: { run: {} } })).toBe(false);
|
|
53
|
+
expect(committedMergeConfig(undefined)).toBe(false);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
describe('parseChangedEntries', () => {
|
|
57
|
+
const raw = (rows) => rows.map(([o, n, s, p]) => `:${o} ${n} ${'1'.repeat(40)} ${'2'.repeat(40)} ${s}\0${p}\0`).join('');
|
|
58
|
+
it('joins raw modes and numstat counts by path; binary is null', () => {
|
|
59
|
+
const r = raw([['100644', '100644', 'M', 'docs/a.md'], ['000000', '100644', 'A', 'img.png']]);
|
|
60
|
+
expect(parseChangedEntries(r, '3\t1\tdocs/a.md\0-\t-\timg.png\0')).toEqual([
|
|
61
|
+
{ path: 'docs/a.md', status: 'M', oldMode: '100644', newMode: '100644', added: 3, deleted: 1 },
|
|
62
|
+
{ path: 'img.png', status: 'A', oldMode: '000000', newMode: '100644', added: null, deleted: null },
|
|
63
|
+
]);
|
|
64
|
+
});
|
|
65
|
+
it('a disagreement or malformed record is null (fail closed)', () => {
|
|
66
|
+
expect(parseChangedEntries(raw([['100644', '100644', 'M', 'a.md']]), '1\t0\tb.md\0')).toBeNull();
|
|
67
|
+
expect(parseChangedEntries(raw([['100644', '100644', 'M', 'a.md'], ['100644', '100644', 'M', 'b.md']]), '1\t0\ta.md\0')).toBeNull();
|
|
68
|
+
expect(parseChangedEntries('garbage\0a.md\0', '1\t0\ta.md\0')).toBeNull();
|
|
69
|
+
expect(parseChangedEntries(raw([['100644', '100644', 'M', 'a.md']]), 'x\ty\ta.md\0')).toBeNull();
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
describe('tiers and denied paths', () => {
|
|
73
|
+
it('docs and tests globs', () => {
|
|
74
|
+
expect(isDocsPath('README.md')).toBe(true);
|
|
75
|
+
expect(isDocsPath('src/x/NOTES.MD')).toBe(false);
|
|
76
|
+
expect(isDocsPath('docs/guide/setup.txt')).toBe(true);
|
|
77
|
+
expect(isDocsPath('src/docs/a.ts')).toBe(false);
|
|
78
|
+
expect(isTestPath('src/a.test.ts')).toBe(true);
|
|
79
|
+
expect(isTestPath('src/__tests__/helpers.ts')).toBe(true);
|
|
80
|
+
expect(isTestPath('pkg/x_test.go')).toBe(true);
|
|
81
|
+
expect(isTestPath('tests/test_api.py')).toBe(true);
|
|
82
|
+
expect(isTestPath('src/a.ts')).toBe(false);
|
|
83
|
+
expect(isTestPath('tests/run.sh')).toBe(false);
|
|
84
|
+
});
|
|
85
|
+
it('CI, config, manifests, lockfiles, agent and factory files are denied anywhere, folded as Windows opens them', () => {
|
|
86
|
+
const paths = [
|
|
87
|
+
'.github/workflows/ci.yml', '.GitHub/CODEOWNERS', '.copilot/omg.jsonc', '.omg/state/x.json', 'pkg/.copilot/backlog/1.md',
|
|
88
|
+
'package.json', 'packages/a/package.json', 'pnpm-lock.yaml', 'yarn.lock', 'Cargo.lock', 'requirements-dev.txt',
|
|
89
|
+
'tsconfig.build.json', 'vitest.config.ts', 'eslint.config.mjs', '.env.local', 'AGENTS.md', 'docs/CLAUDE.md',
|
|
90
|
+
'home/AppData/Roaming/claude-omc/config.jsonc', 'omg.jsonc', '.gitlab-ci.yml', 'azure-pipelines.yml', '.gitattributes',
|
|
91
|
+
'docs/a.md.', 'docs/a:stream.md', 'docs/../.github/x.md', '.circleci/config.yml', 'Jenkinsfile', '.husky/pre-commit',
|
|
92
|
+
];
|
|
93
|
+
expect(deniedPaths(paths)).toEqual(paths.filter((p) => p !== 'docs/a.md.'));
|
|
94
|
+
expect(deniedPaths(['docs/a.md.', 'flaky.json'], ['flaky.json'])).toEqual(['flaky.json']);
|
|
95
|
+
expect(deniedPaths(['docs/guide.md', 'src/a.ts', 'src/a.test.ts'])).toEqual([]);
|
|
96
|
+
});
|
|
97
|
+
it('classifyChanges picks the first enabled tier every file fits', () => {
|
|
98
|
+
expect(classifyChanges([file('README.md'), file('docs/x.md')], all).tier).toBe('docs');
|
|
99
|
+
expect(classifyChanges([file('src/a.test.ts', 200)], all).tier).toBe('tests');
|
|
100
|
+
expect(classifyChanges([file('src/a.ts', 10), file('src/a.test.ts', 10)], all).tier).toBe('small');
|
|
101
|
+
expect(classifyChanges([file('src/a.ts', 81)], all).reasons[0]).toMatch(/no enabled tier fits .*small: 81 changed lines > maxChangedLines 80/);
|
|
102
|
+
expect(classifyChanges([file('src/a.ts')], { enabled: true, tiers: ['docs'] }).reasons[0]).toMatch(/docs: src\/a\.ts is not docs/);
|
|
103
|
+
expect(classifyChanges([file('docs/a.md'), file('docs/b.md')], { enabled: true, tiers: ['docs'], maxFiles: 1 }).reasons[0]).toMatch(/2 files > maxFiles 1/);
|
|
104
|
+
expect(classifyChanges(null, all).reasons[0]).toMatch(/fails closed/);
|
|
105
|
+
expect(classifyChanges([], all).reasons[0]).toMatch(/changes no file/);
|
|
106
|
+
});
|
|
107
|
+
it('adversarial: a docs-only PR with a symlink, an executable bit, a gitlink or a binary never fits', () => {
|
|
108
|
+
expect(classifyChanges([file('docs/a.md'), { ...file('docs/link.md'), oldMode: '000000', newMode: '120000' }], all).reasons[0]).toMatch(/non-plain file modes.*docs\/link\.md 000000->120000/);
|
|
109
|
+
expect(classifyChanges([{ ...file('docs/run.md'), newMode: '100755' }], all).reasons[0]).toMatch(/non-plain/);
|
|
110
|
+
expect(classifyChanges([{ ...file('docs/sub'), oldMode: '000000', newMode: '160000' }], all).reasons[0]).toMatch(/non-plain/);
|
|
111
|
+
expect(classifyChanges([file('docs/a.png', null, null)], all).reasons[0]).toMatch(/binary/);
|
|
112
|
+
});
|
|
113
|
+
it('adversarial: renaming a CI file into docs/ shows its deletion (no renames), which is denied', () => {
|
|
114
|
+
const r = classifyChanges([gone('.github/workflows/ci.yml', 20), added('docs/ci.yml', 20)], all);
|
|
115
|
+
expect(r.tier).toBeUndefined();
|
|
116
|
+
expect(r.reasons[0]).toMatch(/always need a human.*\.github\/workflows\/ci\.yml/);
|
|
117
|
+
});
|
|
118
|
+
it('adversarial: a lane editing user-config-looking files never fits any tier', () => {
|
|
119
|
+
for (const p of ['docs/claude-omc/config.jsonc', 'docs/.copilot/omg.jsonc', 'notes/omc.jsonc', 'docs/.mcp.json']) {
|
|
120
|
+
expect(classifyChanges([file(p)], all).reasons[0], p).toMatch(/always need a human/);
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
describe('review-498 adversarial paths', () => {
|
|
125
|
+
const docsOnly = { enabled: true, tiers: ['docs'] };
|
|
126
|
+
const testsOnly = { enabled: true, tiers: ['tests'] };
|
|
127
|
+
const smallOnly = { enabled: true, tiers: ['small'] };
|
|
128
|
+
it('H1: agent prompts, rules and executable docs never auto-merge in any tier', () => {
|
|
129
|
+
for (const p of ['skills/x/SKILL.md', 'skills/execute/notes.md', 'agents/x.md', 'commands/ship.md', 'templates/pr.md', 'prompts/a.md',
|
|
130
|
+
'.cursor/rules/x.mdc', 'rules/x.mdc', '.gemini/styleguide.md', '.codex/x.md', '.windsurf/rules.md', '.clinerules', '.cursorrules',
|
|
131
|
+
'docs/review.prompt.md', 'notes/x.instructions.md', 'a.chatmode.md', 'docs/.vitepress/config.mts', 'docs/.vitepress/theme/index.ts',
|
|
132
|
+
'.githooks/post-merge', 'hooks/pre-commit', 'scripts/hooks/post-merge', 'src/__mocks__/fs.ts']) {
|
|
133
|
+
expect(deniedPaths([p]), p).toEqual([p]);
|
|
134
|
+
expect(classifyChanges([file(p)], all).tier, p).toBeUndefined();
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
it('H1: the docs tier is an allowlist of .md/.rst (and .txt under docs/): no .mdx, scripts, HTML, site config or images', () => {
|
|
138
|
+
for (const p of ['docs/install.sh', 'docs/install.ps1', 'x.mdx', 'docs/x.mdx', 'docs/index.html', 'docs/site.js', 'docs/logo.svg', 'notes.txt']) {
|
|
139
|
+
expect(isDocsPath(p), p).toBe(false);
|
|
140
|
+
expect(classifyChanges([file(p)], docsOnly).tier, p).toBeUndefined();
|
|
141
|
+
}
|
|
142
|
+
expect(classifyChanges([file('docs/guide.md'), file('README.rst'), file('docs/a.txt')], docsOnly).tier).toBe('docs');
|
|
143
|
+
});
|
|
144
|
+
it('H1: user docsDenied globs keep matching Markdown out of the docs tier', () => {
|
|
145
|
+
const cfg = { ...docsOnly, docsDenied: ['docs/security/', 'RUNBOOK.md'] };
|
|
146
|
+
expect(classifyChanges([file('docs/security/policy.md')], cfg).reasons[0]).toMatch(/docs: docs\/security\/policy\.md is not docs/);
|
|
147
|
+
expect(classifyChanges([file('ops/RUNBOOK.md')], cfg).tier).toBeUndefined();
|
|
148
|
+
expect(classifyChanges([file('docs/guide.md')], cfg).tier).toBe('docs');
|
|
149
|
+
});
|
|
150
|
+
it('M2a/b: test-file names and test directories are anchored', () => {
|
|
151
|
+
expect(isTestPath('lib/latest.rb')).toBe(false);
|
|
152
|
+
expect(isTestPath('lib/contest.rb')).toBe(false);
|
|
153
|
+
expect(isTestPath('spec/user_spec.rb')).toBe(true);
|
|
154
|
+
expect(isTestPath('test.rb')).toBe(true);
|
|
155
|
+
expect(isTestPath('src/cli/commands/test/index.ts')).toBe(false);
|
|
156
|
+
expect(classifyChanges([file('src/cli/commands/test/index.ts')], testsOnly).tier).toBeUndefined();
|
|
157
|
+
expect(isTestPath('tests/helpers.ts')).toBe(true);
|
|
158
|
+
expect(isTestPath('src/deep/__tests__/x.ts')).toBe(true);
|
|
159
|
+
});
|
|
160
|
+
it('M2c: setup files named in the BASE test config, setup/teardown/bench files and __mocks__ never fit the tests tier', () => {
|
|
161
|
+
const testSetup = baseTestSetup([{ path: 'vitest.config.ts', text: "export default { test: { setupFiles: ['./tests/setup.ts'], globalSetup: 'tests/global' } }" }]);
|
|
162
|
+
expect(testSetup).toEqual({ paths: ['./tests/setup.ts', 'tests/global'] });
|
|
163
|
+
const r = classifyChanges([file('tests/setup.ts')], testsOnly, { testSetup });
|
|
164
|
+
expect(r.reasons[0]).toMatch(/base test config runs around every test run.*tests\/setup\.ts/);
|
|
165
|
+
expect(classifyChanges([file('tests/global.ts')], all, { testSetup }).tier).toBeUndefined();
|
|
166
|
+
expect(classifyChanges([file('src/__tests__/setup/x.ts')], testsOnly).tier).toBeUndefined();
|
|
167
|
+
expect(classifyChanges([file('tests/teardown.ts')], testsOnly).tier).toBeUndefined();
|
|
168
|
+
expect(classifyChanges([file('tests/sum.bench.ts')], testsOnly).tier).toBeUndefined();
|
|
169
|
+
expect(classifyChanges([file('__mocks__/x.ts')], all).reasons[0]).toMatch(/always need a human.*__mocks__\/x\.ts/);
|
|
170
|
+
expect(classifyChanges([file('tests/a.test.ts')], testsOnly, { testSetup }).tier).toBe('tests');
|
|
171
|
+
});
|
|
172
|
+
it('M2c: a setup value the engine cannot read as literals keeps the tests and small tiers off (docs still works)', () => {
|
|
173
|
+
for (const text of ['export default { test: { setupFiles: files } }', 'export default { test: { setupFiles: [`${dir}/s.ts`] } }', '{ globalSetup: require("x") }']) {
|
|
174
|
+
const s = baseTestSetup([{ path: 'vitest.config.ts', text }]);
|
|
175
|
+
expect(s.problem, text).toBeTruthy();
|
|
176
|
+
expect(classifyChanges([file('tests/a.test.ts')], all, { testSetup: s }).reasons[0], text).toMatch(/tests: vitest\.config\.ts: (setupFiles|globalSetup) is not/);
|
|
177
|
+
expect(classifyChanges([file('docs/a.md')], all, { testSetup: s }).tier).toBe('docs');
|
|
178
|
+
}
|
|
179
|
+
expect(baseTestSetup([{ path: 'package.json', text: JSON.stringify({ jest: { setupFilesAfterEnv: ['<rootDir>/jest.setup.js'] } }) }])).toEqual({ paths: ['<rootDir>/jest.setup.js'] });
|
|
180
|
+
expect(classifyChanges([file('jest.setup.js')], smallOnly, { testSetup: { paths: ['<rootDir>/jest.setup.js'] } }).tier).toBeUndefined();
|
|
181
|
+
});
|
|
182
|
+
it('M2d: a deleted test file never auto-merges, in any tier', () => {
|
|
183
|
+
expect(classifyChanges([gone('src/a.test.ts')], all).reasons[0]).toMatch(/deletes test files.*src\/a\.test\.ts/);
|
|
184
|
+
expect(classifyChanges([gone('tests/security-regression.ts')], all).tier).toBeUndefined();
|
|
185
|
+
expect(classifyChanges([gone('src/old.ts')], smallOnly).tier).toBe('small');
|
|
186
|
+
});
|
|
187
|
+
it('INFO: the small tier never touches the factory, ship, copilot-run or forge sources, even in a 5-line PR', () => {
|
|
188
|
+
const r = classifyChanges([file('src/factory/run/exec.ts', 3, 2)], smallOnly);
|
|
189
|
+
expect(r.tier).toBeUndefined();
|
|
190
|
+
expect(r.reasons[0]).toMatch(/small: src\/factory\/run\/exec\.ts is not small-tier files/);
|
|
191
|
+
for (const p of ['src/ship/merge.ts', 'src/copilot-run/sandbox.ts', 'src/forge/github/merge.ts', 'SRC/Factory/x.ts'])
|
|
192
|
+
expect(classifyChanges([file(p)], smallOnly).tier, p).toBeUndefined();
|
|
193
|
+
expect(classifyChanges([file('src/greet.ts', 3, 2)], smallOnly).tier).toBe('small');
|
|
194
|
+
});
|
|
195
|
+
it('INFO: user securityCritical globs apply to every tier', () => {
|
|
196
|
+
const cfg = { ...all, securityCritical: ['src/auth/**', '*.guard.ts', 'docs/SECURITY.md'] };
|
|
197
|
+
for (const p of ['src/auth/token.ts', 'src/x/admin.guard.ts', 'docs/SECURITY.md'])
|
|
198
|
+
expect(classifyChanges([file(p)], cfg).reasons[0], p).toMatch(/always need a human/);
|
|
199
|
+
expect(classifyChanges([file('src/authz.ts')], cfg).tier).toBe('small');
|
|
200
|
+
expect(resolveAutoMergeConfig(userWith({ [URL]: { enabled: true, tiers: ['small'], securityCritical: 'src/**' } }), gh).error).toMatch(/securityCritical must be a list/);
|
|
201
|
+
expect(resolveAutoMergeConfig(userWith({ [URL]: { enabled: true, tiers: ['docs'], docsDenied: ['a/'], securityCritical: ['b/'] } }), gh).config).toEqual({ enabled: true, tiers: ['docs'], docsDenied: ['a/'], securityCritical: ['b/'] });
|
|
202
|
+
});
|
|
203
|
+
it('INFO: a configured knownFlakyFile or hooks path is matched however it is spelled', () => {
|
|
204
|
+
expect(deniedPaths(['tests/known-flaky.json'], ['./tests/known-flaky.json'])).toEqual(['tests/known-flaky.json']);
|
|
205
|
+
expect(deniedPaths(['tests/known-flaky.json'], ['.\\Tests\\Known-Flaky.json'])).toEqual(['tests/known-flaky.json']);
|
|
206
|
+
expect(deniedPaths(['myhooks/post-merge'], ['myhooks/'])).toEqual(['myhooks/post-merge']);
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
describe('review-498b adversarial paths', () => {
|
|
210
|
+
const docsOnly = { enabled: true, tiers: ['docs'] };
|
|
211
|
+
const testsOnly = { enabled: true, tiers: ['tests'] };
|
|
212
|
+
const smallOnly = { enabled: true, tiers: ['small'] };
|
|
213
|
+
it('N1: a mission contract or skills-like .md whose blob has frontmatter never fits the docs or small tier', () => {
|
|
214
|
+
// missions/x/sandbox.md: denied by folder and by name even before its frontmatter is read.
|
|
215
|
+
expect(deniedPaths(['missions/x/sandbox.md'])).toEqual(['missions/x/sandbox.md']);
|
|
216
|
+
expect(deniedPaths(['notes/sandbox.md', 'mission.md'])).toEqual(['notes/sandbox.md', 'mission.md']);
|
|
217
|
+
expect(hasFrontmatter('---\nevaluator:\n command: curl x | sh\n---\n# M')).toBe(true);
|
|
218
|
+
expect(hasFrontmatter('\n+++\ntitle = "x"\n+++')).toBe(true);
|
|
219
|
+
expect(hasFrontmatter('# Guide\n\n---\n')).toBe(false);
|
|
220
|
+
const frontmatter = { paths: ['docs/skills-like.md'] };
|
|
221
|
+
const r = classifyChanges([file('docs/skills-like.md')], { enabled: true, tiers: ['docs', 'small'] }, { frontmatter });
|
|
222
|
+
expect(r.tier).toBeUndefined();
|
|
223
|
+
expect(r.reasons[0]).toMatch(/docs: docs\/skills-like\.md start\(s\) with frontmatter.*small: docs\/skills-like\.md start\(s\) with frontmatter/);
|
|
224
|
+
expect(classifyChanges([file('docs/guide.md')], docsOnly, { frontmatter }).tier).toBe('docs');
|
|
225
|
+
// A blob that could not be read keeps the docs and small tiers off.
|
|
226
|
+
expect(classifyChanges([file('docs/guide.md')], docsOnly, { frontmatter: { paths: [], problem: 'docs/guide.md could not be read' } }).reasons[0]).toMatch(/docs: docs\/guide\.md could not be read/);
|
|
227
|
+
});
|
|
228
|
+
it('N2: the docs tier is root README/CHANGELOG/CONTRIBUTING plus docs/**; agent instruction files are denied in every tier', () => {
|
|
229
|
+
for (const p of ['README.md', 'readme.rst', 'CHANGELOG.md', 'CONTRIBUTING.txt', 'README.de.md', 'docs/guide.md', 'docs/a/b.rst', 'docs/notes.txt'])
|
|
230
|
+
expect(isDocsPath(p), p).toBe(true);
|
|
231
|
+
for (const p of ['src/notes.md', 'NOTES.md', 'pkg/README.md', 'docs.md', 'README', 'README.html'])
|
|
232
|
+
expect(isDocsPath(p), p).toBe(false);
|
|
233
|
+
expect(classifyChanges([file('README.md')], docsOnly).tier).toBe('docs');
|
|
234
|
+
expect(classifyChanges([file('docs/guide.md')], docsOnly).tier).toBe('docs');
|
|
235
|
+
expect(classifyChanges([file('src/notes.md')], docsOnly).reasons[0]).toMatch(/docs: src\/notes\.md is not docs/);
|
|
236
|
+
for (const p of ['CLAUDE.local.md', 'AGENTS.override.md', 'WARP.md', 'CONVENTIONS.md', '.omx/plans/x.md', '.junie/guidelines.md', '.amazonq/rules/a.md',
|
|
237
|
+
'.trae/rules/a.md', '.opencode/a.md', '.augment/rules/a.md', '.zed/a.md', 'memory-bank/a.md', '.claude-plugin/plugin.json', 'missions/m/notes.md', 'docs/CLAUDE.local.md']) {
|
|
238
|
+
expect(deniedPaths([p]), p).toEqual([p]);
|
|
239
|
+
expect(classifyChanges([file(p)], all).tier, p).toBeUndefined();
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
it('N2: docsDenied keeps docs that agents are told to read (docs/shared/, docs/partials/) out of the docs tier', () => {
|
|
243
|
+
const cfg = { ...docsOnly, docsDenied: ['docs/shared/', 'docs/partials/'] };
|
|
244
|
+
expect(classifyChanges([file('docs/shared/agent-tiers.md')], cfg).tier).toBeUndefined();
|
|
245
|
+
expect(classifyChanges([file('docs/partials/x.md')], cfg).tier).toBeUndefined();
|
|
246
|
+
expect(classifyChanges([file('docs/guide.md')], cfg).tier).toBe('docs');
|
|
247
|
+
});
|
|
248
|
+
it('N3: files the base package.json runs on install or publish, its bin targets, bridge/ and dist/ are denied in every tier', () => {
|
|
249
|
+
const pkg = JSON.stringify({
|
|
250
|
+
scripts: { postinstall: 'node scripts/postinstall-contained-fs.mjs', prepare: 'npm run build:hooks && husky', 'build:hooks': 'node ./tools/gen-hooks.js --out x', test: 'vitest run scripts/other.mjs' },
|
|
251
|
+
bin: { omg: 'bin/omg.js' },
|
|
252
|
+
});
|
|
253
|
+
const installFiles = baseInstallFiles(pkg);
|
|
254
|
+
expect(installFiles.paths).toEqual(['scripts/postinstall-contained-fs.mjs', 'tools/gen-hooks.js', 'bin/omg.js']);
|
|
255
|
+
for (const p of ['scripts/postinstall-contained-fs.mjs', 'bin/omg.js', 'tools/gen-hooks.js']) {
|
|
256
|
+
expect(classifyChanges([file(p, 1, 1)], all, { installFiles }).reasons[0], p).toMatch(/always need a human/);
|
|
257
|
+
}
|
|
258
|
+
for (const p of ['bridge/cli.cjs', 'dist/index.js', 'dist/README.md'])
|
|
259
|
+
expect(classifyChanges([file(p)], all).reasons[0], p).toMatch(/always need a human/);
|
|
260
|
+
// review-498c L-b: a lifecycle that runs a repository file (whose imports are not followed) keeps the small tier off.
|
|
261
|
+
expect(installFiles.problem).toMatch(/postinstall" runs node scripts\/postinstall-contained-fs\.mjs/);
|
|
262
|
+
expect(classifyChanges([file('scripts/other.mjs')], smallOnly, { installFiles }).tier).toBeUndefined();
|
|
263
|
+
expect(classifyChanges([file('scripts/other.mjs')], smallOnly, { installFiles: baseInstallFiles(JSON.stringify({ scripts: { prepare: 'husky' }, bin: 'cli.js' })) }).tier).toBe('small');
|
|
264
|
+
expect(baseInstallFiles(JSON.stringify({ bin: 'cli.js' }))).toEqual({ paths: ['cli.js'] });
|
|
265
|
+
expect(baseInstallFiles(JSON.stringify({ scripts: { prepare: 'yarn gen', gen: 'node tools/gen.js', prepublishOnly: 'sh ./release.sh' } })).paths).toEqual(['tools/gen.js', 'release.sh']);
|
|
266
|
+
expect(baseInstallFiles(null)).toEqual({ paths: [] });
|
|
267
|
+
});
|
|
268
|
+
it('N3: a lifecycle script the engine cannot read as literal words keeps the small tier off (docs still works)', () => {
|
|
269
|
+
for (const pkg of [{ scripts: { postinstall: 'node $SCRIPT' } }, { scripts: { prepare: 'node scripts/*.js' } }, { scripts: { install: ['x'] } }, { bin: ['a'] }, { scripts: { prepare: 'npm run' } }]) {
|
|
270
|
+
const installFiles = baseInstallFiles(JSON.stringify(pkg));
|
|
271
|
+
expect(installFiles.problem, JSON.stringify(pkg)).toBeTruthy();
|
|
272
|
+
expect(classifyChanges([file('src/greet.ts')], smallOnly, { installFiles }).tier, JSON.stringify(pkg)).toBeUndefined();
|
|
273
|
+
expect(classifyChanges([file('docs/a.md')], all, { installFiles }).tier).toBe('docs');
|
|
274
|
+
}
|
|
275
|
+
expect(baseInstallFiles('{nope').problem).toMatch(/could not be parsed/);
|
|
276
|
+
});
|
|
277
|
+
it('N4: shorthand, computed, merged or imported test config keeps the tests and small tiers off; more runner keys count', () => {
|
|
278
|
+
for (const text of [
|
|
279
|
+
'const setupFiles = ["./tests/env.ts"]; export default { test: { setupFiles } }',
|
|
280
|
+
"export default { test: { ['setupFiles']: ['./x.ts'] } }",
|
|
281
|
+
"import base from './vitest.base'; export default base",
|
|
282
|
+
"const base = require('./jest.base'); module.exports = base",
|
|
283
|
+
"import { mergeConfig } from 'vitest/config'; export default mergeConfig(a, b)",
|
|
284
|
+
"export default defineWorkspace(['packages/*'])",
|
|
285
|
+
"export default { test: { reporters: [['./tests/reporter.ts', {}]] } }",
|
|
286
|
+
]) {
|
|
287
|
+
const s = baseTestSetup([{ path: 'vitest.config.ts', text }]);
|
|
288
|
+
expect(s.problem, text).toBeTruthy();
|
|
289
|
+
expect(classifyChanges([file('tests/a.test.ts')], { enabled: true, tiers: ['tests', 'small'] }, { testSetup: s }).tier, text).toBeUndefined();
|
|
290
|
+
}
|
|
291
|
+
expect(baseTestSetup([{ path: 'vitest.config.ts', text: "export default { test: { environment: 'jsdom', reporters: ['default', './tests/rep.ts'], sequence: { sequencer: './tests/seq.ts' } } }" }]))
|
|
292
|
+
.toEqual({ paths: ['jsdom', 'default', './tests/rep.ts', './tests/seq.ts'] });
|
|
293
|
+
expect(baseTestSetup([{ path: 'package.json', text: JSON.stringify({ jest: { testEnvironment: './tests/env.js', transform: { '^.+\\.ts$': ['ts-jest', { a: 1 }] }, reporters: ['default', ['./tests/reporter.js', {}]] } }) }]))
|
|
294
|
+
.toEqual({ paths: ['default', './tests/reporter.js', './tests/env.js', 'ts-jest'] });
|
|
295
|
+
// The name backstop: environment and reporter files never fit the tests tier.
|
|
296
|
+
for (const p of ['tests/env.ts', 'tests/reporter.ts', 'tests/global-setup.ts', 'tests/serializer.ts'])
|
|
297
|
+
expect(classifyChanges([file(p)], testsOnly).tier, p).toBeUndefined();
|
|
298
|
+
});
|
|
299
|
+
it('N5: a gutted test (more lines deleted than added) or an added skip, focus or empty assertion fits no tests or small tier', () => {
|
|
300
|
+
expect(classifyChanges([file('src/a.test.ts', 1, 200)], all).tier).toBeUndefined();
|
|
301
|
+
expect(classifyChanges([file('src/a.test.ts', 1, 200)], all).reasons[0]).toMatch(/tests: src\/a\.test\.ts lose\(s\) more lines \(or assertion lines\) than it gains/);
|
|
302
|
+
for (const line of [" it.skip('checks auth', () => {", "describe.only('x', () => {", 'xit("x", () => {', " it.todo('later')", ' expect(true).toBe(true);', 'test.skipIf(process.env.CI)("x", () => {']) {
|
|
303
|
+
const patch = patchLines(`diff --git a/src/a.test.ts b/src/a.test.ts\n--- a/src/a.test.ts\n+++ b/src/a.test.ts\n@@ -1,1 +1,2 @@\n ctx\n+${line}\n`);
|
|
304
|
+
expect(patch).toEqual([{ path: 'b/src/a.test.ts', sign: '+', text: line }]);
|
|
305
|
+
const r = classifyChanges([file('src/a.test.ts', 1, 0)], { enabled: true, tiers: ['tests', 'small'] }, { patch });
|
|
306
|
+
expect(r.tier, line).toBeUndefined();
|
|
307
|
+
expect(r.reasons[0], line).toMatch(/tests: an added line skips, focuses or empties a test/);
|
|
308
|
+
}
|
|
309
|
+
expect(classifyChanges([file('src/a.test.ts', 3, 0)], testsOnly, { patch: [{ path: 'b/src/a.test.ts', sign: '+', text: " it('works', () => expect(sum(1, 2)).toBe(3));" }] }).tier).toBe('tests');
|
|
310
|
+
// An unreadable patch (or a coloured one) keeps the tests and small tiers off; docs never reads it.
|
|
311
|
+
expect(patchLines('\u001b[32m+x\u001b[m')).toBeNull();
|
|
312
|
+
expect(classifyChanges([file('src/a.test.ts')], testsOnly, { patch: null }).reasons[0]).toMatch(/patch could not be read/);
|
|
313
|
+
expect(classifyChanges([file('docs/a.md')], docsOnly, { patch: null }).tier).toBe('docs');
|
|
314
|
+
});
|
|
315
|
+
});
|
|
316
|
+
describe('review-498c follow-ups (fail closed)', () => {
|
|
317
|
+
const docsOnly = { enabled: true, tiers: ['docs'] };
|
|
318
|
+
const testsOnly = { enabled: true, tiers: ['tests'] };
|
|
319
|
+
const smallOnly = { enabled: true, tiers: ['small'] };
|
|
320
|
+
const testsSmall = { enabled: true, tiers: ['tests', 'small'] };
|
|
321
|
+
it('L-a: a docs path in a non-canonical spelling is read for frontmatter and never fits the docs tier', () => {
|
|
322
|
+
for (const p of ['README.md.', 'README.md ', 'README.md', 'README.md', 'docs/x.md.', 'docs/x.md', 'docs/x.md', 'Docs./x.md', 'docs/x.md']) {
|
|
323
|
+
expect(isFrontmatterCandidate(p), p).toBe(true);
|
|
324
|
+
expect(classifyChanges([file(p)], docsOnly).tier, p).toBeUndefined();
|
|
325
|
+
}
|
|
326
|
+
// A small-tier file spelled to dodge the Markdown test is read for frontmatter too.
|
|
327
|
+
expect(isFrontmatterCandidate('src/notes.md')).toBe(true);
|
|
328
|
+
expect(isFrontmatterCandidate('src/x.ts')).toBe(false);
|
|
329
|
+
for (const p of ['README.md', 'readme.MD', 'docs/guide.md', 'CHANGELOG.rst'])
|
|
330
|
+
expect(classifyChanges([file(p)], docsOnly).tier, p).toBe('docs');
|
|
331
|
+
});
|
|
332
|
+
it('L-b: install scripts the engine cannot follow keep the small tier off', () => {
|
|
333
|
+
const tools = { setup: 'node tools/setup.js' };
|
|
334
|
+
for (const pkg of [
|
|
335
|
+
{ scripts: { postinstall: 'node .' } },
|
|
336
|
+
{ scripts: { postinstall: 'node lib' } },
|
|
337
|
+
{ scripts: { postinstall: 'node scripts/postinstall' } },
|
|
338
|
+
{ scripts: { postinstall: "node -e \"require('./lib/install')\"" } },
|
|
339
|
+
{ scripts: { postinstall: 'npm run -s setup', ...tools } },
|
|
340
|
+
{ scripts: { postinstall: 'npm --silent run setup', ...tools } },
|
|
341
|
+
{ scripts: { postinstall: 'pnpm -s setup', ...tools } },
|
|
342
|
+
{ scripts: { postinstall: 'run-s setup', ...tools } },
|
|
343
|
+
{ scripts: { postinstall: 'npm-run-all setup', ...tools } },
|
|
344
|
+
{ scripts: { postinstall: 'concurrently "npm:setup"', ...tools } },
|
|
345
|
+
{ scripts: { postinstall: 'npx --yes ./tools/x' } },
|
|
346
|
+
{ scripts: { postinstall: 'npm run setup -w pkg-a', setup: 'husky' } },
|
|
347
|
+
{ scripts: { install: 'node-gyp rebuild' } },
|
|
348
|
+
{ scripts: { dependencies: 'husky && tsx tools/dep.ts' } },
|
|
349
|
+
{ scripts: { preprepare: 'node tools/pp.js' } },
|
|
350
|
+
{ scripts: { postprepare: 'node tools/pq.js' } },
|
|
351
|
+
{ scripts: { postinstall: 'yarn workspace a build' } },
|
|
352
|
+
{ scripts: { prepare: 'bun tools/x.ts' } },
|
|
353
|
+
{ gypfile: true },
|
|
354
|
+
{ workspaces: ['packages/*'] },
|
|
355
|
+
]) {
|
|
356
|
+
const installFiles = baseInstallFiles(JSON.stringify(pkg));
|
|
357
|
+
expect(installFiles.problem, JSON.stringify(pkg)).toBeTruthy();
|
|
358
|
+
expect(classifyChanges([file('src/greet.ts')], smallOnly, { installFiles }).tier, JSON.stringify(pkg)).toBeUndefined();
|
|
359
|
+
}
|
|
360
|
+
for (const root of [['binding.gyp'], ['pnpm-workspace.yaml'], ['Binding.GYP']]) {
|
|
361
|
+
expect(baseInstallFiles(null, root).problem, root[0]).toBeTruthy();
|
|
362
|
+
expect(baseInstallFiles(JSON.stringify({ scripts: { prepare: 'husky' } }), root).problem, root[0]).toBeTruthy();
|
|
363
|
+
}
|
|
364
|
+
// Commands that run no repository file stay fine: the small tier still works.
|
|
365
|
+
for (const pkg of [{ scripts: { prepare: 'husky' } }, { scripts: { prepare: 'npm run hooks', hooks: 'husky' } }, { scripts: { postinstall: 'yarn && husky' } }, { scripts: { test: 'node scripts/t.js' } }]) {
|
|
366
|
+
const installFiles = baseInstallFiles(JSON.stringify(pkg), ['package.json', 'src']);
|
|
367
|
+
expect(installFiles.problem, JSON.stringify(pkg)).toBeUndefined();
|
|
368
|
+
expect(classifyChanges([file('src/greet.ts')], smallOnly, { installFiles }).tier, JSON.stringify(pkg)).toBe('small');
|
|
369
|
+
}
|
|
370
|
+
});
|
|
371
|
+
it('L-c: more skip and empty-assertion spellings, and assertion loss hidden by padding, keep the tests and small tiers off', () => {
|
|
372
|
+
const one = (line, path = 'tests/a.test.ts') => classifyChanges([file(path, 1, 1)], testsSmall, { patch: [{ path: `b/${path}`, sign: '+', text: line }] });
|
|
373
|
+
for (const line of ["it['skip']('x', () => {})", 'it[`skip`]("x")', "if (false) it('x', f)", 'expect(x).toBe(x)', 'expect(!0).toBe(true)', 'expect.assertions(0)', "it.each([])('x')", 'return; // early', "self.skipTest('x')", "pytest.skip('x')", "describe.concurrent.skip('x')"]) {
|
|
374
|
+
expect(one(line).tier, line).toBeUndefined();
|
|
375
|
+
expect(one(line).reasons[0], line).toMatch(/an added line skips, focuses or empties a test/);
|
|
376
|
+
}
|
|
377
|
+
// Test-file-only patterns do not fire in source: an early return is ordinary code.
|
|
378
|
+
expect(one(' return;', 'src/greet.ts').tier).toBe('small');
|
|
379
|
+
expect(one(" it('adds', () => expect(sum(1, 2)).toBe(3));").tier).toBe('tests');
|
|
380
|
+
// +200/-200 with the assertions swapped for padding: still gutted.
|
|
381
|
+
const padded = [
|
|
382
|
+
...Array.from({ length: 3 }, (_, n) => ({ path: 'b/tests/a.test.ts', sign: '-', text: ` expect(auth(${n})).toBe(false);` })),
|
|
383
|
+
...Array.from({ length: 3 }, () => ({ path: 'b/tests/a.test.ts', sign: '+', text: ' // pad' })),
|
|
384
|
+
];
|
|
385
|
+
const r = classifyChanges([file('tests/a.test.ts', 200, 200)], testsSmall, { patch: padded });
|
|
386
|
+
expect(r.tier).toBeUndefined();
|
|
387
|
+
expect(r.reasons[0]).toMatch(/lose\(s\) more lines \(or assertion lines\)/);
|
|
388
|
+
// A rewritten assertion (one out, one in) is fine.
|
|
389
|
+
expect(classifyChanges([file('tests/a.test.ts', 1, 1)], testsOnly, { patch: [{ ...padded[0] }, { path: 'b/tests/a.test.ts', sign: '+', text: ' expect(auth(0)).toBe(true);' }] }).tier).toBe('tests');
|
|
390
|
+
// The patch parser keeps each line's file, deletions included.
|
|
391
|
+
expect(patchLines('diff --git a/x.ts b/x.ts\n--- a/x.ts\n+++ b/x.ts\n@@ -1 +1 @@\n-old\n+new\ndiff --git a/t.test.ts b/t.test.ts\n--- a/t.test.ts\n+++ /dev/null\n@@ -1 +0,0 @@\n---- a/y\n'))
|
|
392
|
+
.toEqual([{ path: 'b/x.ts', sign: '-', text: 'old' }, { path: 'b/x.ts', sign: '+', text: 'new' }, { path: 'a/t.test.ts', sign: '-', text: '--- a/y' }]);
|
|
393
|
+
});
|
|
394
|
+
it('L-d: projects, workspace, extends, foreign imports, computed loads and more runner keys keep the tests and small tiers off', () => {
|
|
395
|
+
for (const [text, path] of [
|
|
396
|
+
["import base from '@repo/vitest-config'; export default defineConfig({ ...base })", 'vitest.config.ts'],
|
|
397
|
+
["export default defineConfig({ test: { projects: ['packages/*'] } })", 'vitest.config.ts'],
|
|
398
|
+
["export default defineConfig({ test: { workspace: ['packages/*'] } })", 'vitest.config.ts'],
|
|
399
|
+
["export default { test: { extends: './vitest.base.ts' } }", 'vitest.config.ts'],
|
|
400
|
+
["import base from 'src/vitest.base'; export default base", 'vitest.config.ts'],
|
|
401
|
+
["import base from '/abs/vitest.base'; export default base", 'vitest.config.ts'],
|
|
402
|
+
['const r = require(`${__dirname}/base`); module.exports = r', 'jest.config.js'],
|
|
403
|
+
["module.exports = require(path.join(__dirname, 'base'))", 'jest.config.js'],
|
|
404
|
+
[JSON.stringify({ jest: { projects: ['<rootDir>/packages/*'], setupFiles: ['./s.js'] } }), 'package.json'],
|
|
405
|
+
]) {
|
|
406
|
+
const s = baseTestSetup([{ path, text }]);
|
|
407
|
+
expect(s.problem, text).toBeTruthy();
|
|
408
|
+
expect(classifyChanges([file('tests/a.test.ts')], testsSmall, { testSetup: s }).tier, text).toBeUndefined();
|
|
409
|
+
}
|
|
410
|
+
expect(baseTestSetup([{ path: 'vitest.config.ts', text: "export default { test: { setupFiles: ['./a.ts'], pool: './tools/p.ts', typecheck: { checker: './tools/tc.ts' }, coverage: { provider: 'custom', customProviderModule: './tools/cov.ts' } } }" }]))
|
|
411
|
+
.toEqual({ paths: ['./a.ts', './tools/p.ts', './tools/tc.ts', './tools/cov.ts'] });
|
|
412
|
+
// vitest, vite and node builtins (and a JSDoc type import) stay readable.
|
|
413
|
+
expect(baseTestSetup([{ path: 'vitest.config.ts', text: "import { defineConfig } from 'vitest/config';\nimport { resolve } from 'node:path';\n/** @type {import('vitest').UserConfig} */\nexport default defineConfig({ test: { setupFiles: ['./tests/setup.ts'] } })" }]))
|
|
414
|
+
.toEqual({ paths: ['./tests/setup.ts'] });
|
|
415
|
+
});
|
|
416
|
+
it('L-e: git hook names at the repository root (core.hooksPath ".") fit no tier', () => {
|
|
417
|
+
for (const p of ['post-merge', 'post-checkout', 'pre-commit', 'POST-MERGE', 'post-merge.', 'post-merge.exe', 'reference-transaction']) {
|
|
418
|
+
expect(deniedPaths([p]), p).toEqual([p]);
|
|
419
|
+
expect(classifyChanges([added(p)], all).tier, p).toBeUndefined();
|
|
420
|
+
}
|
|
421
|
+
expect(deniedPaths(['src/post-merge.ts', 'docs/pre-commit.md'])).toEqual([]);
|
|
422
|
+
});
|
|
423
|
+
});
|
|
424
|
+
describe('autoMergeVerdict', () => {
|
|
425
|
+
const ok = {
|
|
426
|
+
head: HEAD,
|
|
427
|
+
config: all,
|
|
428
|
+
run: { ciHeal: false, forgeKind: 'github', history: [{ note: 'implement' }] },
|
|
429
|
+
decision: { ok: true, reasons: [], checks: ['Test', 'Lint'], blocking: [] },
|
|
430
|
+
verdict: { sha: HEAD, verdict: 'approve', reviewer: 'factory-review' },
|
|
431
|
+
human: { commentOnly: 0 },
|
|
432
|
+
labels: ['factory'],
|
|
433
|
+
changes: classifyChanges([file('docs/a.md')], all),
|
|
434
|
+
};
|
|
435
|
+
it('all conditions hold: ok with the tier and one evidence line per condition', () => {
|
|
436
|
+
const v = autoMergeVerdict(ok);
|
|
437
|
+
expect(v).toMatchObject({ ok: true, tier: 'docs', reasons: [] });
|
|
438
|
+
expect(v.evidence.join('\n')).toMatch(/CI green at aaaaaaaaaaaa: `Test`, `Lint`/);
|
|
439
|
+
expect(v.evidence.join('\n')).toMatch(/every file fits tier docs/);
|
|
440
|
+
expect(autoMergeComment('issue #3', 'docs', HEAD, v.evidence, 'the factory')).toMatch(/^Factory run for issue #3: auto-merged by tier docs at aaaaaaaaaaaa/);
|
|
441
|
+
});
|
|
442
|
+
it('a benign earlier park (the human merge, a CI failure a fix round solved) does not block, and a required check that succeeded counts', () => {
|
|
443
|
+
const history = [{ note: 'awaiting-human: merge: merge is a human step' }, { note: 'awaiting-human: ci-failed: Test failed' }];
|
|
444
|
+
expect(autoMergeVerdict({ ...ok, run: { ...ok.run, history }, requiredChecks: ['Test'] })).toMatchObject({ ok: true, tier: 'docs' });
|
|
445
|
+
// N6: with required checks set, a skipped non-required check (a docs-only path filter) does not block.
|
|
446
|
+
expect(autoMergeVerdict({ ...ok, decision: { ok: true, reasons: [], checks: ['Test'], unsettled: ['Docs preview'], blocking: [] }, requiredChecks: ['Test'] })).toMatchObject({ ok: true });
|
|
447
|
+
});
|
|
448
|
+
it('forge-reported check names reach the park text and evidence only as sanitised code spans', () => {
|
|
449
|
+
const evil = '[click](http://x.test) owner/repo#1 @user\nline2 | cell `tick`';
|
|
450
|
+
const park = autoMergeVerdict({ ...ok, decision: { ok: true, reasons: [], checks: ['labeler'], unsettled: [evil], blocking: [] } }).reasons.join('\n');
|
|
451
|
+
expect(park).toContain('`[click](http://x.test) owner/repo#1 @user line2 ¦ cell \'tick\'`');
|
|
452
|
+
expect(park).not.toMatch(/[@|]|\n.*line2/);
|
|
453
|
+
const good = autoMergeVerdict({ ...ok, decision: { ok: true, reasons: [], checks: [evil], blocking: [] } });
|
|
454
|
+
expect(good.evidence.join('\n')).toContain('`[click](http://x.test) owner/repo#1 @user line2 ¦ cell \'tick\'` succeeded');
|
|
455
|
+
// Decisions still use the raw names: the required check matches by its raw name.
|
|
456
|
+
expect(autoMergeVerdict({ ...ok, decision: { ok: true, reasons: [], checks: [evil], blocking: [] }, requiredChecks: [evil] }).ok).toBe(true);
|
|
457
|
+
});
|
|
458
|
+
const fails = [
|
|
459
|
+
['Azure DevOps', { run: { ...ok.run, forgeKind: 'azure-devops' } }, /Azure DevOps PRs always merge by a human/],
|
|
460
|
+
['ci-heal', { run: { ...ok.run, ciHeal: true } }, /ci-heal runs/],
|
|
461
|
+
['merge rule reason', { decision: { ok: false, reasons: ['PR is a draft'], checks: ['Test'] } }, /merge rule has reasons: PR is a draft/],
|
|
462
|
+
['verdict on another head', { verdict: { sha: OTHER, verdict: 'approve', reviewer: 'r' } }, /did not approve this exact head/],
|
|
463
|
+
['changes requested', { verdict: { sha: HEAD, verdict: 'changes-requested', reviewer: 'r' } }, /did not approve/],
|
|
464
|
+
['no verdict', { verdict: undefined }, /latest: none/],
|
|
465
|
+
['no CI configured', { decision: { ok: true, reasons: [], noChecks: true, checks: [] } }, /no CI check succeeded/],
|
|
466
|
+
['empty check list', { decision: { ok: true, reasons: [], checks: [] } }, /no CI check succeeded/],
|
|
467
|
+
// M1: every check SKIPPED (paths-ignore on a docs PR): mergeDecision passes no succeeded check, so nothing counts.
|
|
468
|
+
['all checks skipped', { decision: { ok: true, reasons: [], checks: [] } }, /skipped, neutral or no checks never auto-merge/],
|
|
469
|
+
// N6: no required checks and a labeler SUCCESS while the tests were SKIPPED: every check must succeed.
|
|
470
|
+
['labeler-only SUCCESS with skipped tests', { decision: { ok: true, reasons: [], checks: ['labeler'], unsettled: ['Test'] } }, /checks skipped or neutral on this head \(`Test`\); without required checks every check must succeed/],
|
|
471
|
+
['required check did not run', { decision: { ok: true, reasons: [], checks: ['Lint'] }, requiredChecks: ['Test'] }, /no required check \(`Test`\) succeeded/],
|
|
472
|
+
// INFO: the history check is an allowlist: an unknown park keeps the merge human.
|
|
473
|
+
['unknown park in history', { run: { ...ok.run, history: [{ note: 'awaiting-human: some-future-park: why' }] } }, /parked at some-future-park/],
|
|
474
|
+
['human review off', { human: undefined }, /factory\.review\.human is "off"/],
|
|
475
|
+
['comment-only review', { human: { commentOnly: 1 } }, /1 comment-only human review/],
|
|
476
|
+
['manual-merge label', { labels: ['Factory:Manual-Merge'] }, new RegExp(`carries ${MANUAL_MERGE_LABEL}`)],
|
|
477
|
+
['labels unreadable', { labels: null }, /labels could not be read/],
|
|
478
|
+
['secret park', { run: { ...ok.run, history: [{ note: 'awaiting-human: secret-shaped-content: lane x: ...' }] } }, /parked at secret-shaped-content/],
|
|
479
|
+
['tamper hold', { run: { ...ok.run, history: [{ note: 'tamper hold released' }] } }, /tamper or quarantine/],
|
|
480
|
+
['unsandboxed lanes ack', { run: { ...ok.run, unsandboxedAck: HEAD } }, /--allow-unsandboxed-lanes/],
|
|
481
|
+
['unsandboxed gates ack', { run: { ...ok.run, unsandboxedGatesAck: HEAD } }, /--allow-unsandboxed-gates/],
|
|
482
|
+
['gate change ack', { run: { ...ok.run, gateChangeApproved: 'x' } }, /--allow-gate-change/],
|
|
483
|
+
['secret ack', { run: { ...ok.run, secretAck: [{}] } }, /--allow-secret-shapes/],
|
|
484
|
+
['allow flag in history', { run: { ...ok.run, history: [{ note: 'accepted (--allow-unsandboxed-lanes)' }] } }, /an --allow-\* flag/],
|
|
485
|
+
['tier miss', { changes: classifyChanges([file('package.json')], all) }, /always need a human/],
|
|
486
|
+
];
|
|
487
|
+
for (const [name, over, reason] of fails) {
|
|
488
|
+
it(`refuses: ${name}`, () => {
|
|
489
|
+
const v = autoMergeVerdict({ ...ok, ...over });
|
|
490
|
+
expect(v.ok).toBe(false);
|
|
491
|
+
expect(v.tier).toBeUndefined();
|
|
492
|
+
expect(v.reasons.join('\n')).toMatch(reason);
|
|
493
|
+
});
|
|
494
|
+
}
|
|
495
|
+
});
|
|
496
|
+
describe('the GitHub auto-merge shape and the factory guard', () => {
|
|
497
|
+
const step = { repo: 'github.com/o/r', pr: 12, head: HEAD };
|
|
498
|
+
const args = githubAutoMergeArgs(step);
|
|
499
|
+
it('is a head-pinned REST merge without an admin bypass', () => {
|
|
500
|
+
expect(args).toEqual(['api', '--hostname', 'github.com', '--method', 'PUT', 'repos/o/r/pulls/12/merge', '-f', `sha=${HEAD}`, '-f', 'merge_method=merge']);
|
|
501
|
+
expect(githubAutoMergeArgs({ ...step, head: 'HEAD' })).toBeUndefined();
|
|
502
|
+
expect(githubAutoMergeArgs({ ...step, repo: 'github.com/../r' })).toBeUndefined();
|
|
503
|
+
expect(githubAutoMergeArgs({ ...step, pr: 0 })).toBeUndefined();
|
|
504
|
+
});
|
|
505
|
+
it('the guard admits it only inside the engine step for exactly that repository, PR and sha', () => {
|
|
506
|
+
expect(isGithubAutoMergeArgs(args, step)).toBe(true);
|
|
507
|
+
expect(isGithubAutoMergeArgs(args, undefined)).toBe(false);
|
|
508
|
+
expect(isGithubAutoMergeArgs(args, { ...step, head: OTHER })).toBe(false);
|
|
509
|
+
expect(isGithubAutoMergeArgs(args, { ...step, pr: 13 })).toBe(false);
|
|
510
|
+
const ctx = (autoMerge) => ({ repo: 'github.com/o/r', ...(autoMerge ? { autoMerge } : {}) });
|
|
511
|
+
expect(() => assertFactoryCommand('gh', args, [], undefined, undefined, undefined, undefined, ctx({ pr: 12, head: HEAD }))).not.toThrow();
|
|
512
|
+
expect(() => assertFactoryCommand('gh', args, [], undefined, undefined, undefined, undefined, ctx())).toThrow(FactorySafetyError);
|
|
513
|
+
expect(() => assertFactoryCommand('gh', args, [], undefined, undefined, undefined, undefined, ctx({ pr: 12, head: OTHER }))).toThrow(FactorySafetyError);
|
|
514
|
+
// `gh pr merge` stays refused, in or out of the step.
|
|
515
|
+
expect(() => assertFactoryCommand('gh', ['pr', 'merge', '12', '--admin', '--merge', '--match-head-commit', HEAD], [], undefined, undefined, undefined, undefined, ctx({ pr: 12, head: HEAD }))).toThrow(FactorySafetyError);
|
|
516
|
+
// A variant with the admin bypass or another method is not the shape.
|
|
517
|
+
const swapped = [...args];
|
|
518
|
+
swapped[4] = 'POST';
|
|
519
|
+
expect(() => assertFactoryCommand('gh', swapped, [], undefined, undefined, undefined, undefined, ctx({ pr: 12, head: HEAD }))).toThrow(FactorySafetyError);
|
|
520
|
+
});
|
|
521
|
+
it('the guard admits the two diff reads of the tier check and nothing wider', () => {
|
|
522
|
+
const range = `${OTHER}...${HEAD}`;
|
|
523
|
+
for (const flag of ['--raw', '--numstat']) {
|
|
524
|
+
expect(() => assertFactoryCommand('git', ['diff', '--no-ext-diff', '--no-textconv', flag, '-z', '--no-renames', '--no-abbrev', range])).not.toThrow();
|
|
525
|
+
}
|
|
526
|
+
expect(() => assertFactoryCommand('git', ['diff', '--no-ext-diff', '--no-textconv', '--raw', '-z', '--no-renames', '--output=/tmp/x', range])).toThrow();
|
|
527
|
+
});
|
|
528
|
+
it('the guard admits the base root listing, the core.hooksPath read and the merge-commit read, exact shape only', () => {
|
|
529
|
+
expect(() => assertFactoryCommand('git', ['ls-tree', '-z', '--name-only', OTHER])).not.toThrow();
|
|
530
|
+
expect(() => assertFactoryCommand('git', ['ls-tree', '-z', '--name-only', 'HEAD'])).toThrow();
|
|
531
|
+
expect(() => assertFactoryCommand('git', ['config', '--show-scope', '--get-all', 'core.hooksPath'])).not.toThrow();
|
|
532
|
+
expect(() => assertFactoryCommand('git', ['config', '--show-scope', '--get-all', 'core.sshCommand'])).toThrow();
|
|
533
|
+
const ctx = { repo: 'github.com/o/r' };
|
|
534
|
+
const read = githubCommitReadArgs('github.com/o/r', HEAD);
|
|
535
|
+
expect(read).toEqual(['api', '--hostname', 'github.com', `repos/o/r/commits/${HEAD}`]);
|
|
536
|
+
expect(() => assertFactoryCommand('gh', read, [], undefined, undefined, undefined, undefined, ctx)).not.toThrow();
|
|
537
|
+
expect(() => assertFactoryCommand('gh', githubCommitReadArgs('github.com/o/other', HEAD), [], undefined, undefined, undefined, undefined, ctx)).toThrow(FactorySafetyError);
|
|
538
|
+
expect(() => assertFactoryCommand('gh', [...read, '--method', 'POST'], [], undefined, undefined, undefined, undefined, ctx)).toThrow(FactorySafetyError);
|
|
539
|
+
});
|
|
540
|
+
});
|
|
541
|
+
//# sourceMappingURL=auto-merge.test.js.map
|