@diffci.com/diffci 0.3.54 → 0.3.55
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/dist-client/src/client/agent-selection.d.ts +9 -2
- package/dist-client/src/client/agent-selection.js +20 -8
- package/dist-client/src/client/agent-setup.js +1 -1
- package/dist-client/src/client/cli.js +15 -4
- package/dist-client/src/client/command-batches.js +3 -2
- package/dist-client/src/client/context.js +32 -2
- package/dist-client/src/client/coverage-map.js +6 -1
- package/dist-client/src/client/full-command.js +19 -14
- package/dist-client/src/client/hook.d.ts +17 -0
- package/dist-client/src/client/hook.js +53 -1
- package/dist-client/src/client/install.d.ts +6 -0
- package/dist-client/src/client/install.js +29 -1
- package/dist-client/src/client/mcp.js +4 -0
- package/dist-client/src/client/observe.js +3 -2
- package/dist-client/src/client/report.d.ts +1 -1
- package/dist-client/src/client/shared-graph-cache.js +4 -2
- package/dist-client/src/client/telemetry.js +2 -1
- package/dist-client/src/client/usage-signal.d.ts +1 -1
- package/dist-client/src/client/verify-savings.d.ts +6 -0
- package/dist-client/src/client/verify-savings.js +15 -3
- package/dist-client/src/client/verify.js +124 -22
- package/node_modules/@diffci.com/core/README.md +17 -10
- package/node_modules/@diffci.com/core/dist/ci-inference/expression.d.ts +5 -0
- package/node_modules/@diffci.com/core/dist/ci-inference/expression.js +38 -5
- package/node_modules/@diffci.com/core/dist/ci-inference/expression.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/ci-inference/infer.js +26 -6
- package/node_modules/@diffci.com/core/dist/ci-inference/infer.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/ci-inference/jobs.d.ts +2 -1
- package/node_modules/@diffci.com/core/dist/ci-inference/jobs.js +7 -2
- package/node_modules/@diffci.com/core/dist/ci-inference/jobs.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/ci-inference/matrix.js +15 -8
- package/node_modules/@diffci.com/core/dist/ci-inference/matrix.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/ci-inference/purpose.js +6 -2
- package/node_modules/@diffci.com/core/dist/ci-inference/purpose.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/ci-inference/resolve.js +19 -4
- package/node_modules/@diffci.com/core/dist/ci-inference/resolve.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/git/ci-config-paths.js +13 -1
- package/node_modules/@diffci.com/core/dist/git/ci-config-paths.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/git/git-diff.d.ts +5 -0
- package/node_modules/@diffci.com/core/dist/git/git-diff.js +22 -20
- package/node_modules/@diffci.com/core/dist/git/git-diff.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/planner/check-narrowing.js +22 -1
- package/node_modules/@diffci.com/core/dist/planner/check-narrowing.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/planner/pipeline-steps.d.ts +6 -0
- package/node_modules/@diffci.com/core/dist/planner/pipeline-steps.js +14 -2
- package/node_modules/@diffci.com/core/dist/planner/pipeline-steps.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/planner/planner.js +65 -14
- package/node_modules/@diffci.com/core/dist/planner/planner.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/planner/rust-command.js +43 -1
- package/node_modules/@diffci.com/core/dist/planner/rust-command.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/planner/script-reads.js +5 -2
- package/node_modules/@diffci.com/core/dist/planner/script-reads.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/planner/test-command.js +17 -2
- package/node_modules/@diffci.com/core/dist/planner/test-command.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/planner/type-program.js +27 -1
- package/node_modules/@diffci.com/core/dist/planner/type-program.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/adapters/go.js +5 -1
- package/node_modules/@diffci.com/core/dist/repo/adapters/go.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/adapters/maven.js +21 -2
- package/node_modules/@diffci.com/core/dist/repo/adapters/maven.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/adapters/python.d.ts +9 -1
- package/node_modules/@diffci.com/core/dist/repo/adapters/python.js +158 -14
- package/node_modules/@diffci.com/core/dist/repo/adapters/python.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/adapters/rust.d.ts +1 -0
- package/node_modules/@diffci.com/core/dist/repo/adapters/rust.js +180 -15
- package/node_modules/@diffci.com/core/dist/repo/adapters/rust.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/adapters/types.d.ts +7 -0
- package/node_modules/@diffci.com/core/dist/repo/adapters/types.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/file-references.d.ts +16 -0
- package/node_modules/@diffci.com/core/dist/repo/file-references.js +76 -5
- package/node_modules/@diffci.com/core/dist/repo/file-references.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/graph.js +100 -29
- package/node_modules/@diffci.com/core/dist/repo/graph.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/impact.d.ts +7 -0
- package/node_modules/@diffci.com/core/dist/repo/impact.js +55 -8
- package/node_modules/@diffci.com/core/dist/repo/impact.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/layout.js +4 -1
- package/node_modules/@diffci.com/core/dist/repo/layout.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/runner-universe.js +10 -1
- package/node_modules/@diffci.com/core/dist/repo/runner-universe.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/script-universe.js +1 -1
- package/node_modules/@diffci.com/core/dist/repo/script-universe.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/test-discovery.js +5 -1
- package/node_modules/@diffci.com/core/dist/repo/test-discovery.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/types.d.ts +3 -0
- package/node_modules/@diffci.com/core/dist/repo/workflow-test-steps.js +3 -3
- package/node_modules/@diffci.com/core/dist/repo/workflow-test-steps.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/research/baseline/matcher.js +65 -13
- package/node_modules/@diffci.com/core/dist/research/baseline/matcher.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/research/baseline/workflow-parser.js +47 -2
- package/node_modules/@diffci.com/core/dist/research/baseline/workflow-parser.js.map +1 -1
- package/node_modules/@diffci.com/core/package.json +1 -0
- package/node_modules/@diffci.com/core/src/ci-inference/expression.ts +38 -5
- package/node_modules/@diffci.com/core/src/ci-inference/infer.ts +21 -6
- package/node_modules/@diffci.com/core/src/ci-inference/jobs.ts +7 -2
- package/node_modules/@diffci.com/core/src/ci-inference/matrix.ts +15 -8
- package/node_modules/@diffci.com/core/src/ci-inference/purpose.ts +6 -2
- package/node_modules/@diffci.com/core/src/ci-inference/resolve.ts +18 -4
- package/node_modules/@diffci.com/core/src/git/ci-config-paths.ts +8 -1
- package/node_modules/@diffci.com/core/src/git/git-diff.ts +20 -21
- package/node_modules/@diffci.com/core/src/planner/check-narrowing.ts +22 -1
- package/node_modules/@diffci.com/core/src/planner/pipeline-steps.ts +13 -2
- package/node_modules/@diffci.com/core/src/planner/planner.ts +42 -14
- package/node_modules/@diffci.com/core/src/planner/rust-command.ts +37 -1
- package/node_modules/@diffci.com/core/src/planner/script-reads.ts +5 -1
- package/node_modules/@diffci.com/core/src/planner/test-command.ts +17 -2
- package/node_modules/@diffci.com/core/src/planner/type-program.ts +25 -1
- package/node_modules/@diffci.com/core/src/repo/adapters/go.ts +5 -1
- package/node_modules/@diffci.com/core/src/repo/adapters/maven.ts +20 -2
- package/node_modules/@diffci.com/core/src/repo/adapters/python.ts +133 -14
- package/node_modules/@diffci.com/core/src/repo/adapters/rust.ts +136 -16
- package/node_modules/@diffci.com/core/src/repo/adapters/types.ts +7 -1
- package/node_modules/@diffci.com/core/src/repo/file-references.ts +70 -5
- package/node_modules/@diffci.com/core/src/repo/graph.ts +81 -20
- package/node_modules/@diffci.com/core/src/repo/impact.ts +56 -7
- package/node_modules/@diffci.com/core/src/repo/layout.ts +5 -1
- package/node_modules/@diffci.com/core/src/repo/runner-universe.ts +11 -1
- package/node_modules/@diffci.com/core/src/repo/script-universe.ts +1 -1
- package/node_modules/@diffci.com/core/src/repo/test-discovery.ts +4 -1
- package/node_modules/@diffci.com/core/src/repo/types.ts +3 -1
- package/node_modules/@diffci.com/core/src/repo/workflow-test-steps.ts +3 -3
- package/node_modules/@diffci.com/core/src/research/baseline/matcher.ts +43 -13
- package/node_modules/@diffci.com/core/src/research/baseline/workflow-parser.ts +44 -2
- package/package.json +2 -2
|
@@ -48,8 +48,15 @@ export declare function agentSelection(repoInput: string): Promise<{
|
|
|
48
48
|
tests_selected: number;
|
|
49
49
|
command: string | undefined;
|
|
50
50
|
}>;
|
|
51
|
-
/**
|
|
52
|
-
|
|
51
|
+
/**
|
|
52
|
+
* A path as one shell word in POSIX shells, cmd.exe and PowerShell, or undefined when no quoting is
|
|
53
|
+
* literal in all three. Inside double quotes `$` and backticks still expand (POSIX, PowerShell), `%` and
|
|
54
|
+
* `!` expand in cmd.exe, and `\` and `"` cannot be escaped the same way in each. The agent runs this
|
|
55
|
+
* command as written, so a repository file named `$(…).ts` must never reach it (CodeQL alert 36).
|
|
56
|
+
*/
|
|
57
|
+
export declare function shellPath(path: string): string | undefined;
|
|
58
|
+
/** The one command that verifies `scope` in isolation, as `diffci_select_tests` returns it, or undefined when a path cannot be quoted safely. */
|
|
59
|
+
export declare function scopedVerifyCommand(repoPath: string, scope: VerificationTreeScope, version?: string): string | undefined;
|
|
53
60
|
/**
|
|
54
61
|
* The plan for HEAD plus only the staged files, or only the named files (2026-11-17), made in the same
|
|
55
62
|
* temporary worktree `verify --staged` / `--paths` verifies in. Its `command` is that one verify
|
|
@@ -9,8 +9,9 @@ import { createIsolatedWorktree } from "./isolated-worktree.js";
|
|
|
9
9
|
import { requireDiffciPackageIdentity } from "./package-identity.js";
|
|
10
10
|
import { executableSelection, scopedChanges } from "./verify.js";
|
|
11
11
|
import { captureScopedTree, captureWorkingTreeSnapshot } from "./working-tree.js";
|
|
12
|
+
/** A rename is its old path and its new one: whatever imported the old path is affected too. */
|
|
12
13
|
function changedPaths(repoPath, snapshot) {
|
|
13
|
-
return execFileSync("git", ["diff", "--name-only", "-z", snapshot.baseSha, snapshot.commitSha], {
|
|
14
|
+
return execFileSync("git", ["diff", "--name-only", "--no-renames", "-z", snapshot.baseSha, snapshot.commitSha], {
|
|
14
15
|
cwd: repoPath, encoding: "utf8", windowsHide: true,
|
|
15
16
|
}).split("\0").filter(Boolean);
|
|
16
17
|
}
|
|
@@ -98,17 +99,26 @@ function diffciInvocation(repoPath, version) {
|
|
|
98
99
|
return hookCommand("npm", version);
|
|
99
100
|
}
|
|
100
101
|
}
|
|
101
|
-
/**
|
|
102
|
-
|
|
103
|
-
|
|
102
|
+
/**
|
|
103
|
+
* A path as one shell word in POSIX shells, cmd.exe and PowerShell, or undefined when no quoting is
|
|
104
|
+
* literal in all three. Inside double quotes `$` and backticks still expand (POSIX, PowerShell), `%` and
|
|
105
|
+
* `!` expand in cmd.exe, and `\` and `"` cannot be escaped the same way in each. The agent runs this
|
|
106
|
+
* command as written, so a repository file named `$(…).ts` must never reach it (CodeQL alert 36).
|
|
107
|
+
*/
|
|
108
|
+
export function shellPath(path) {
|
|
109
|
+
if (/^[A-Za-z0-9_./@+-]+$/.test(path))
|
|
110
|
+
return path;
|
|
111
|
+
return /[$`"\\%!\0-\x1f\x7f]/.test(path) ? undefined : `"${path}"`;
|
|
104
112
|
}
|
|
105
|
-
/** The one command that verifies `scope` in isolation, as `diffci_select_tests` returns it. */
|
|
113
|
+
/** The one command that verifies `scope` in isolation, as `diffci_select_tests` returns it, or undefined when a path cannot be quoted safely. */
|
|
106
114
|
export function scopedVerifyCommand(repoPath, scope, version = requireDiffciPackageIdentity().version) {
|
|
107
115
|
const run = diffciInvocation(repoPath, version);
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
116
|
+
if (scope.kind === "staged")
|
|
117
|
+
return `${run} verify --staged --json`;
|
|
118
|
+
const words = scope.paths.map(shellPath);
|
|
119
|
+
return words.every((word) => word !== undefined) ? `${run} verify --json --paths ${words.join(" ")}` : undefined;
|
|
111
120
|
}
|
|
121
|
+
const UNQUOTABLE_PATH = "a path contains a character no shell quoting keeps literal ($ ` \" \\ % ! or a control character), so DiffCI returns no command to paste; stage the files and use scope \"staged\", or run `diffci verify --paths` with the path quoted for your shell";
|
|
112
122
|
/**
|
|
113
123
|
* The plan for HEAD plus only the staged files, or only the named files (2026-11-17), made in the same
|
|
114
124
|
* temporary worktree `verify --staged` / `--paths` verifies in. Its `command` is that one verify
|
|
@@ -134,6 +144,8 @@ export async function agentScopedSelection(repoInput, scope) {
|
|
|
134
144
|
});
|
|
135
145
|
if (!scoped.changed)
|
|
136
146
|
return unplanned("planned", scope.kind === "staged" ? "nothing is staged: the index matches HEAD" : "the given paths do not differ from HEAD");
|
|
147
|
+
if (command === undefined)
|
|
148
|
+
return unplanned("blocked", UNQUOTABLE_PATH);
|
|
137
149
|
const worktree = createIsolatedWorktree(repoPath, scoped.baseSha, scoped.treeSha);
|
|
138
150
|
if ("error" in worktree)
|
|
139
151
|
return unplanned("blocked", worktree.error);
|
|
@@ -54,7 +54,7 @@ export function mcpServerEntry(version) {
|
|
|
54
54
|
command: "node",
|
|
55
55
|
args: [
|
|
56
56
|
"-e",
|
|
57
|
-
`const { spawn } = require('node:child_process'); const npxArgs = ['--yes', '--package', '@diffci.com/diffci@${version}', 'diffci-mcp']; const child = process.platform === 'win32' ? spawn(process.env.ComSpec || 'cmd.exe', ['/d', '/s', '/c', 'npx', ...npxArgs], { stdio: 'inherit' }); child.once('error', (error) => { console.error('Failed to launch DiffCI MCP:', error.message); process.exit(1); }); child.once('exit', (code, signal) => process.exit(code ?? (signal ? 1 : 0)));`,
|
|
57
|
+
`const { spawn } = require('node:child_process'); const npxArgs = ['--yes', '--package', '@diffci.com/diffci@${version}', 'diffci-mcp']; const child = process.platform === 'win32' ? spawn(process.env.ComSpec || 'cmd.exe', ['/d', '/s', '/c', 'npx', ...npxArgs], { stdio: 'inherit' }) : spawn('npx', npxArgs, { stdio: 'inherit' }); child.once('error', (error) => { console.error('Failed to launch DiffCI MCP:', error.message); process.exit(1); }); child.once('exit', (code, signal) => process.exit(code ?? (signal ? 1 : 0)));`,
|
|
58
58
|
],
|
|
59
59
|
};
|
|
60
60
|
}
|
|
@@ -46,7 +46,7 @@ import { observe, isInsideRepository } from "./observe.js";
|
|
|
46
46
|
import { resolveObservationAgent } from "./agent-identity.js";
|
|
47
47
|
import { inferFullCommand, inferComparableSelectedCommand, inferWorkspaceComparison } from "./full-command.js";
|
|
48
48
|
import { addDiffciPackageScripts, detectPackageManager, installDiffci } from "./install.js";
|
|
49
|
-
import { hookCommand, installPrePushHook, isGitRepository } from "./hook.js";
|
|
49
|
+
import { hookCommand, installPrePushHook, isGitRepository, refreshPrePushHook } from "./hook.js";
|
|
50
50
|
import { AGENT_HOOK_TIMEOUT_SECONDS, ignoredWrites, MCP_CONFIG_PATHS, SKILL_PATHS, writeAgentStopHook, writeMcpConfig, writeSkill } from "./agent-setup.js";
|
|
51
51
|
import { submitObservation } from "./submit.js";
|
|
52
52
|
import { configureGraphCache } from "./shared-graph-cache.js";
|
|
@@ -684,6 +684,15 @@ async function runVerifyCommand(flags, env) {
|
|
|
684
684
|
console.error(`diffci: ${outside} changed file(s) here are not staged and were verified too. If other sessions share this checkout, stage your own files and run \`diffci verify --staged\` (or \`diffci verify --paths <file...>\`) to verify HEAD plus only those, in a temporary worktree.`);
|
|
685
685
|
}
|
|
686
686
|
}
|
|
687
|
+
// Never from the hook's own `verify --base/--head`, and never in CI, where no hook is installed.
|
|
688
|
+
if ((changed || staged || paths) && env.DIFFCI_HOOK_REFRESH !== "0" && !(Boolean(env.CI) && env.CI !== "false")) {
|
|
689
|
+
try {
|
|
690
|
+
const refreshed = refreshPrePushHook(repoPath);
|
|
691
|
+
if (refreshed)
|
|
692
|
+
console.error(refreshed);
|
|
693
|
+
}
|
|
694
|
+
catch { /* keeping an old hook never fails verification */ }
|
|
695
|
+
}
|
|
687
696
|
await recordUsage("verify", report.verification, identity.version, flags, env, repoPath);
|
|
688
697
|
if (flags["no-log"] !== true)
|
|
689
698
|
appendOutcome(repoPath, report, env);
|
|
@@ -1533,11 +1542,11 @@ Usage:
|
|
|
1533
1542
|
diffci verify [--changed | --staged | --paths <file...> | --paths-from <file|-> | --base <sha> --head <sha>]
|
|
1534
1543
|
[--policy enforce] [--repo <path>] [--out <file>] [--json]
|
|
1535
1544
|
[--redact-paths] [--timeout-ms <ms>] [--baseline-on-failure] [--no-checks | --checks]
|
|
1536
|
-
[--
|
|
1545
|
+
[--no-send] [--no-log] [--no-reuse] [--no-rank] [--fail-fast]
|
|
1537
1546
|
[--shard <i/N> [--timings <file>]] [--no-coverage]
|
|
1538
1547
|
diffci telemetry [--mode repo|count-only] [--internal-usage]
|
|
1539
1548
|
diffci check [--repo <path>] [--out <file>] [--base <sha> --head <sha>]
|
|
1540
|
-
[--redact-paths] [--json] [--quiet] [--fail-on-error] [--timeout-ms <ms>]
|
|
1549
|
+
[--redact-paths] [--json] [--quiet] [--fail-on-error] [--timeout-ms <ms>]
|
|
1541
1550
|
diffci plan --base <sha> [--head <sha>] [--repo <path>]
|
|
1542
1551
|
diffci check-plan --plan <plan.json> --results <junit.xml>
|
|
1543
1552
|
diffci red-builds <owner/repo> [--runs <n>] [--workflow <id|file>] [--json <file>] [--check-jobs <regex>] [--ci-only-jobs <regex>]
|
|
@@ -1546,7 +1555,7 @@ Usage:
|
|
|
1546
1555
|
[--label <name>] [--repository-url <https-url>] [--redact-paths]
|
|
1547
1556
|
diffci observe [--repo <path>] [--out <file>] [--base <sha> --head <sha>]
|
|
1548
1557
|
[--redact-paths] [--json] [--quiet] [--fail-on-error] [--summary-out <file.md>]
|
|
1549
|
-
[--api-url <url> --api-token <token>] [--no-send] [--
|
|
1558
|
+
[--api-url <url> --api-token <token>] [--no-send] [--agent <name|auto>]
|
|
1550
1559
|
[--graph-cache-dir <dir>] [--shared-graph-cache [--graph-cache-url <url>]]
|
|
1551
1560
|
diffci verify-savings --repo <path> --full <command>
|
|
1552
1561
|
(--selected <command> | --selected-from-report <file>)
|
|
@@ -1580,6 +1589,8 @@ and adds diffci:verify, diffci:check, and diffci:observe package scripts without
|
|
|
1580
1589
|
--verification-workflow adds a blocking GitHub check that uploads a commit-bound verification receipt.
|
|
1581
1590
|
The pre-push hook runs diffci verify on the commits being pushed and blocks the push
|
|
1582
1591
|
when verification fails (git push --no-verify skips it; DIFFCI_HOOK_STRICT=1 also blocks when it cannot verify).
|
|
1592
|
+
verify --changed, --staged and --paths replace an outdated DiffCI-written hook with this version's, same
|
|
1593
|
+
command (DIFFCI_HOOK_REFRESH=0 turns it off; a hook DiffCI did not write is never touched).
|
|
1583
1594
|
mcp runs the stdio MCP server for native agent integrations.
|
|
1584
1595
|
verify --changed snapshots staged, unstaged, and non-ignored untracked changes, runs the minimum
|
|
1585
1596
|
executable verification (or full fallback), and exits zero only when that exact snapshot passes.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { commandArguments } from "./selected-coverage.js";
|
|
2
2
|
import { mergeTestFileResults } from "./test-results.js";
|
|
3
|
-
import { measureCommand } from "./verify-savings.js";
|
|
3
|
+
import { measureCommand, tail as tailBytes } from "./verify-savings.js";
|
|
4
4
|
/**
|
|
5
5
|
* Selected-test commands too long for the shell (2026-10-21).
|
|
6
6
|
*
|
|
@@ -149,7 +149,8 @@ export function measureCommands(commands, options) {
|
|
|
149
149
|
const failingTests = [...new Set(parts.flatMap((part) => part.failingTests ?? []))].sort();
|
|
150
150
|
const counted = ranAll && parts.every((part) => part.runnerTestCount !== undefined);
|
|
151
151
|
const testResults = mergeTestFileResults(...parts.map((part) => part.testResults));
|
|
152
|
-
|
|
152
|
+
// The same byte-bounded cut as a single command's tail: by UTF-8 bytes, at a character boundary.
|
|
153
|
+
const tail = (key) => tailBytes(parts.map((part) => part[key]).join(""), options.tailBytes);
|
|
153
154
|
return {
|
|
154
155
|
command: commands.join(" && "),
|
|
155
156
|
exitCode: failed ? failed.exitCode : ranAll ? 0 : null,
|
|
@@ -129,6 +129,24 @@ function mergeBase(git, a, b) {
|
|
|
129
129
|
const result = git(["merge-base", a, b]);
|
|
130
130
|
return result.ok ? result.stdout.trim() || undefined : undefined;
|
|
131
131
|
}
|
|
132
|
+
/**
|
|
133
|
+
* The base for a push that created its branch (2026-11-18). There is no `before`, and the head's parent
|
|
134
|
+
* covers only the last of the commits the push brought, so a change made earlier in the same push was
|
|
135
|
+
* never analysed. The commits the new branch adds are the ones not on the default branch, so the merge
|
|
136
|
+
* base with the default branch's remote-tracking ref is the base - the same range a pull request from the
|
|
137
|
+
* branch would get. Undefined when that ref is not in this checkout, or the head is already on it (nothing
|
|
138
|
+
* new to compare), and the caller then falls back to the labelled `head-parent` range.
|
|
139
|
+
*/
|
|
140
|
+
function branchCreationBase(git, headSha, defaultBranch) {
|
|
141
|
+
if (!defaultBranch || !/^[A-Za-z0-9._/-]+$/.test(defaultBranch) || defaultBranch.startsWith("-") || defaultBranch.includes("..")) {
|
|
142
|
+
return undefined;
|
|
143
|
+
}
|
|
144
|
+
const tip = resolveSha(git, `refs/remotes/origin/${defaultBranch}`);
|
|
145
|
+
if (!tip)
|
|
146
|
+
return undefined;
|
|
147
|
+
const common = mergeBase(git, tip, headSha);
|
|
148
|
+
return common && common !== headSha && commitExists(git, common) ? common : undefined;
|
|
149
|
+
}
|
|
132
150
|
/** The one sentence every "commit missing locally" refusal ends with, so the fix is never a guess. */
|
|
133
151
|
const DEEPEN_HINT = "the commit is not in this checkout - add `fetch-depth: 0` to the actions/checkout step in the job that runs DiffCI (this does not affect any other job)";
|
|
134
152
|
/** GitLab clones 20 commits deep by default, so a long merge request loses its base (2026-11-05). */
|
|
@@ -237,6 +255,11 @@ function resolveGitlabRange(env, git) {
|
|
|
237
255
|
if (before && before !== ZERO_SHA && commitExists(git, before)) {
|
|
238
256
|
return { ok: true, range: { baseSha: before, headSha, source: "push-event" } };
|
|
239
257
|
}
|
|
258
|
+
if (before === ZERO_SHA || before === undefined) {
|
|
259
|
+
const common = branchCreationBase(git, headSha, asString(env.CI_DEFAULT_BRANCH));
|
|
260
|
+
if (common)
|
|
261
|
+
return { ok: true, range: { baseSha: common, headSha, source: "push-event", mergeBaseSha: common } };
|
|
262
|
+
}
|
|
240
263
|
const parent = resolveSha(git, `${headSha}^`);
|
|
241
264
|
if (!parent) {
|
|
242
265
|
return {
|
|
@@ -344,8 +367,15 @@ export function resolveCommitRange(options) {
|
|
|
344
367
|
if (before && before !== ZERO_SHA && commitExists(git, before)) {
|
|
345
368
|
return { ok: true, range: { baseSha: before, headSha, source: "push-event" } };
|
|
346
369
|
}
|
|
347
|
-
// A branch's first push has no `before`.
|
|
348
|
-
//
|
|
370
|
+
// A branch's first push has no `before`. Its merge base with the default branch covers every commit
|
|
371
|
+
// the push brought; only when that cannot be computed is the head's own parent used, labelled as
|
|
372
|
+
// such - it answers "what did this commit change", not "what did this push change".
|
|
373
|
+
if (before === ZERO_SHA) {
|
|
374
|
+
const defaultBranch = asString(nested(payload, "repository", "default_branch")) ?? asString(env.GITHUB_DEFAULT_BRANCH);
|
|
375
|
+
const common = branchCreationBase(git, headSha, defaultBranch);
|
|
376
|
+
if (common)
|
|
377
|
+
return { ok: true, range: { baseSha: common, headSha, source: "push-event", mergeBaseSha: common } };
|
|
378
|
+
}
|
|
349
379
|
const parent = resolveSha(git, `${headSha}^`);
|
|
350
380
|
if (!parent) {
|
|
351
381
|
return {
|
|
@@ -25,12 +25,17 @@ export const COVERAGE_MAP_SCHEMA = "diffci.coverage-map.v1";
|
|
|
25
25
|
const PROBE = `"use strict";
|
|
26
26
|
if (process.env.NODE_TEST_CONTEXT && process.argv[1] && process.env.DIFFCI_COVERAGE_LOG) {
|
|
27
27
|
const fs = require("node:fs");
|
|
28
|
+
const { resolve } = require("node:path");
|
|
28
29
|
const { fileURLToPath } = require("node:url");
|
|
29
30
|
const file = process.argv[1];
|
|
30
31
|
const reads = new Set();
|
|
31
32
|
const listed = new Set();
|
|
33
|
+
// A relative path is resolved against the test process's working directory when it is read, as fs does.
|
|
32
34
|
const note = (set, target) => {
|
|
33
|
-
try {
|
|
35
|
+
try {
|
|
36
|
+
const name = typeof target === "string" ? target : target instanceof URL ? fileURLToPath(target) : Buffer.isBuffer(target) ? target.toString() : "";
|
|
37
|
+
if (name) set.add(resolve(name));
|
|
38
|
+
} catch {}
|
|
34
39
|
};
|
|
35
40
|
const wrap = (owner, name, set) => {
|
|
36
41
|
const original = owner[name];
|
|
@@ -144,6 +144,9 @@ export function inferFullCommand(repoPath) {
|
|
|
144
144
|
};
|
|
145
145
|
}
|
|
146
146
|
const packagePath = join(repoPath, "package.json");
|
|
147
|
+
// A package.json without a test script is often tooling only (prettier, husky, commitlint) beside a
|
|
148
|
+
// Go or Python project, whose own runner is then the full command, as it is for the selection.
|
|
149
|
+
let noTestScript;
|
|
147
150
|
if (existsSync(packagePath)) {
|
|
148
151
|
let pkg;
|
|
149
152
|
try {
|
|
@@ -153,21 +156,23 @@ export function inferFullCommand(repoPath) {
|
|
|
153
156
|
return { reason: "package.json could not be read" };
|
|
154
157
|
}
|
|
155
158
|
if (typeof pkg.scripts?.test !== "string" || !pkg.scripts.test.trim()) {
|
|
156
|
-
|
|
159
|
+
noTestScript = { reason: "package.json has no test script" };
|
|
157
160
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
+
else {
|
|
162
|
+
const manager = typeof pkg.packageManager === "string" ? pkg.packageManager.split("@")[0] : undefined;
|
|
163
|
+
if (manager === "pnpm" || manager === "yarn" || manager === "bun") {
|
|
164
|
+
return { command: `${manager} test`, reason: `package.json test script via ${manager}` };
|
|
165
|
+
}
|
|
166
|
+
if (manager && manager !== "npm")
|
|
167
|
+
return { reason: `unsupported package manager: ${manager}` };
|
|
168
|
+
if (existsSync(join(repoPath, "pnpm-lock.yaml")))
|
|
169
|
+
return { command: "pnpm test", reason: "package.json test script with pnpm lockfile" };
|
|
170
|
+
if (existsSync(join(repoPath, "yarn.lock")))
|
|
171
|
+
return { command: "yarn test", reason: "package.json test script with Yarn lockfile" };
|
|
172
|
+
if (existsSync(join(repoPath, "bun.lock")) || existsSync(join(repoPath, "bun.lockb")))
|
|
173
|
+
return { command: "bun test", reason: "package.json test script with Bun lockfile" };
|
|
174
|
+
return { command: "npm test", reason: "package.json test script" };
|
|
161
175
|
}
|
|
162
|
-
if (manager && manager !== "npm")
|
|
163
|
-
return { reason: `unsupported package manager: ${manager}` };
|
|
164
|
-
if (existsSync(join(repoPath, "pnpm-lock.yaml")))
|
|
165
|
-
return { command: "pnpm test", reason: "package.json test script with pnpm lockfile" };
|
|
166
|
-
if (existsSync(join(repoPath, "yarn.lock")))
|
|
167
|
-
return { command: "yarn test", reason: "package.json test script with Yarn lockfile" };
|
|
168
|
-
if (existsSync(join(repoPath, "bun.lock")) || existsSync(join(repoPath, "bun.lockb")))
|
|
169
|
-
return { command: "bun test", reason: "package.json test script with Bun lockfile" };
|
|
170
|
-
return { command: "npm test", reason: "package.json test script" };
|
|
171
176
|
}
|
|
172
177
|
if (existsSync(join(repoPath, "go.mod")))
|
|
173
178
|
return { command: "go test ./...", reason: "root Go module" };
|
|
@@ -178,7 +183,7 @@ export function inferFullCommand(repoPath) {
|
|
|
178
183
|
? { command: `${interpreter} -m pytest`, reason: "Python project tested with pytest" }
|
|
179
184
|
: { reason: "Python project, but no Python 3 interpreter (python3, python or py -3) is on PATH" };
|
|
180
185
|
}
|
|
181
|
-
return { reason: "no supported full test command could be inferred" };
|
|
186
|
+
return noTestScript ?? { reason: "no supported full test command could be inferred" };
|
|
182
187
|
}
|
|
183
188
|
function pythonInterpreter(cwd) {
|
|
184
189
|
for (const candidate of [["python3"], ["python"], ["py", "-3"]]) {
|
|
@@ -39,3 +39,20 @@ export declare function isGitRepository(repoPath: string): boolean;
|
|
|
39
39
|
/** Writes the hook into the directory Git actually runs hooks from (`core.hooksPath` included, such as
|
|
40
40
|
* `.husky`). An existing hook DiffCI did not write is kept unless `force` is set. */
|
|
41
41
|
export declare function installPrePushHook(repoPath: string, command: string, force: boolean): string;
|
|
42
|
+
/** The DiffCI command a managed hook was written for, read from its in-place verify line (every version has it). */
|
|
43
|
+
export declare function hookCommandOf(hook: string): string | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* Keeps an installed DiffCI pre-push hook current (2026-11-17).
|
|
46
|
+
*
|
|
47
|
+
* WHY. Repositories keep the hook `diffci init` wrote first, so hook fixes never reached them. DentalPresence's
|
|
48
|
+
* hook of 8 Nov predated the not-installed fix: pushing from a worktree without node_modules, npx printed a
|
|
49
|
+
* 404, the old hook read it as failing tests and blocked a correct push. The current hook says it could not
|
|
50
|
+
* verify and lets the push through.
|
|
51
|
+
*
|
|
52
|
+
* WHAT. When it differs from the hook this version writes for the same command, a hook with DiffCI's marker is
|
|
53
|
+
* replaced; any other hook is never touched. The new file is written beside it and renamed over it, so a
|
|
54
|
+
* hook another push is running keeps reading the old file. Callers run it only outside the hook's own
|
|
55
|
+
* commands (verify of the working tree, the index or paths, never `verify --base/--head`) and ignore any
|
|
56
|
+
* error. `DIFFCI_HOOK_REFRESH=0` turns it off.
|
|
57
|
+
*/
|
|
58
|
+
export declare function refreshPrePushHook(repoPath: string): string | undefined;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { execFileSync } from "node:child_process";
|
|
2
|
-
import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { chmodSync, existsSync, mkdirSync, readFileSync, renameSync, unlinkSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { dirname, isAbsolute, join, relative } from "node:path";
|
|
4
4
|
/**
|
|
5
5
|
* The pre-push hook `diffci init` installs (2026-10-28; on by default since 0.3.24).
|
|
@@ -208,3 +208,55 @@ export function installPrePushHook(repoPath, command, force) {
|
|
|
208
208
|
catch { /* Git for Windows runs hooks through sh regardless of mode. */ }
|
|
209
209
|
return `wrote ${shown} (verifies pushed commits; skip once with git push --no-verify)`;
|
|
210
210
|
}
|
|
211
|
+
/** The DiffCI command a managed hook was written for, read from its in-place verify line (every version has it). */
|
|
212
|
+
export function hookCommandOf(hook) {
|
|
213
|
+
const match = /^[ \t]*(\S.*?) verify --base "\$base" --head "\$local_sha" <\/dev\/null[ \t]*$/m.exec(hook.replace(/\r\n/g, "\n"));
|
|
214
|
+
return match?.[1];
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Keeps an installed DiffCI pre-push hook current (2026-11-17).
|
|
218
|
+
*
|
|
219
|
+
* WHY. Repositories keep the hook `diffci init` wrote first, so hook fixes never reached them. DentalPresence's
|
|
220
|
+
* hook of 8 Nov predated the not-installed fix: pushing from a worktree without node_modules, npx printed a
|
|
221
|
+
* 404, the old hook read it as failing tests and blocked a correct push. The current hook says it could not
|
|
222
|
+
* verify and lets the push through.
|
|
223
|
+
*
|
|
224
|
+
* WHAT. When it differs from the hook this version writes for the same command, a hook with DiffCI's marker is
|
|
225
|
+
* replaced; any other hook is never touched. The new file is written beside it and renamed over it, so a
|
|
226
|
+
* hook another push is running keeps reading the old file. Callers run it only outside the hook's own
|
|
227
|
+
* commands (verify of the working tree, the index or paths, never `verify --base/--head`) and ignore any
|
|
228
|
+
* error. `DIFFCI_HOOK_REFRESH=0` turns it off.
|
|
229
|
+
*/
|
|
230
|
+
export function refreshPrePushHook(repoPath) {
|
|
231
|
+
const hooksDir = execFileSync("git", ["rev-parse", "--git-path", "hooks"], { cwd: repoPath, encoding: "utf8", windowsHide: true, stdio: ["ignore", "pipe", "ignore"] }).trim();
|
|
232
|
+
const hookPath = join(isAbsolute(hooksDir) ? hooksDir : join(repoPath, hooksDir), "pre-push");
|
|
233
|
+
if (!existsSync(hookPath))
|
|
234
|
+
return undefined;
|
|
235
|
+
const existing = readFileSync(hookPath, "utf8");
|
|
236
|
+
if (!existing.includes(HOOK_MARKER))
|
|
237
|
+
return undefined;
|
|
238
|
+
const command = hookCommandOf(existing);
|
|
239
|
+
if (!command)
|
|
240
|
+
return undefined;
|
|
241
|
+
const content = prePushHook(command);
|
|
242
|
+
if (existing.replace(/\r\n/g, "\n") === content)
|
|
243
|
+
return undefined;
|
|
244
|
+
const temporary = `${hookPath}.diffci-${process.pid}`;
|
|
245
|
+
writeFileSync(temporary, content, "utf8");
|
|
246
|
+
try {
|
|
247
|
+
chmodSync(temporary, 0o755);
|
|
248
|
+
}
|
|
249
|
+
catch { /* Git for Windows runs hooks through sh regardless of mode. */ }
|
|
250
|
+
try {
|
|
251
|
+
renameSync(temporary, hookPath);
|
|
252
|
+
}
|
|
253
|
+
catch (error) {
|
|
254
|
+
try {
|
|
255
|
+
unlinkSync(temporary);
|
|
256
|
+
}
|
|
257
|
+
catch { /* nothing left to clean */ }
|
|
258
|
+
throw error;
|
|
259
|
+
}
|
|
260
|
+
const shown = relative(repoPath, hookPath).replace(/\\/g, "/") || hookPath;
|
|
261
|
+
return `diffci: updated the DiffCI pre-push hook ${shown} to this version's (same command: ${command}); DIFFCI_HOOK_REFRESH=0 turns this off`;
|
|
262
|
+
}
|
|
@@ -11,6 +11,12 @@ export interface PackageScriptResult {
|
|
|
11
11
|
kept: string[];
|
|
12
12
|
}
|
|
13
13
|
export declare function detectPackageManager(repoPath: string): SupportedPackageManager;
|
|
14
|
+
/**
|
|
15
|
+
* Whether the repository uses Yarn 2 or later (Berry). Berry's `yarn add` rejects `--ignore-scripts`
|
|
16
|
+
* ("Unsupported option name") and skips build scripts with `--mode=skip-build` instead. The declared
|
|
17
|
+
* packageManager version decides; without one, a .yarnrc.yml or a Berry lockfile (`__metadata:`) does.
|
|
18
|
+
*/
|
|
19
|
+
export declare function usesYarnBerry(repoPath: string): boolean;
|
|
14
20
|
export declare function installPlan(repoPath: string, version: string, platform?: NodeJS.Platform): InstallPlan;
|
|
15
21
|
export declare function installDiffci(repoPath: string, version: string, run?: typeof spawnSync, packageSpecOverride?: string): {
|
|
16
22
|
plan: InstallPlan;
|
|
@@ -41,6 +41,32 @@ export function detectPackageManager(repoPath) {
|
|
|
41
41
|
}
|
|
42
42
|
return detected.values().next().value ?? "npm";
|
|
43
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* Whether the repository uses Yarn 2 or later (Berry). Berry's `yarn add` rejects `--ignore-scripts`
|
|
46
|
+
* ("Unsupported option name") and skips build scripts with `--mode=skip-build` instead. The declared
|
|
47
|
+
* packageManager version decides; without one, a .yarnrc.yml or a Berry lockfile (`__metadata:`) does.
|
|
48
|
+
*/
|
|
49
|
+
export function usesYarnBerry(repoPath) {
|
|
50
|
+
const packagePath = join(repoPath, "package.json");
|
|
51
|
+
let declared;
|
|
52
|
+
try {
|
|
53
|
+
declared = JSON.parse(readFileSync(packagePath, "utf8")).packageManager;
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
declared = undefined;
|
|
57
|
+
}
|
|
58
|
+
const version = typeof declared === "string" ? /^yarn@(\d+)/.exec(declared.trim()) : null;
|
|
59
|
+
if (version)
|
|
60
|
+
return Number(version[1]) >= 2;
|
|
61
|
+
if (existsSync(join(repoPath, ".yarnrc.yml")))
|
|
62
|
+
return true;
|
|
63
|
+
try {
|
|
64
|
+
return /^__metadata:/m.test(readFileSync(join(repoPath, "yarn.lock"), "utf8"));
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
44
70
|
export function installPlan(repoPath, version, platform = process.platform) {
|
|
45
71
|
const manager = detectPackageManager(repoPath);
|
|
46
72
|
const packageSpec = `@diffci.com/diffci@${version}`;
|
|
@@ -48,7 +74,9 @@ export function installPlan(repoPath, version, platform = process.platform) {
|
|
|
48
74
|
const argsByManager = {
|
|
49
75
|
npm: ["install", "--save-dev", "--save-exact", "--ignore-scripts", packageSpec],
|
|
50
76
|
pnpm: ["add", "--save-dev", "--save-exact", "--ignore-scripts", packageSpec],
|
|
51
|
-
yarn:
|
|
77
|
+
yarn: manager === "yarn" && usesYarnBerry(repoPath)
|
|
78
|
+
? ["add", "--dev", "--exact", "--mode=skip-build", packageSpec]
|
|
79
|
+
: ["add", "--dev", "--exact", "--ignore-scripts", packageSpec],
|
|
52
80
|
bun: ["add", "--dev", "--exact", "--ignore-scripts", packageSpec],
|
|
53
81
|
};
|
|
54
82
|
const managerArgs = argsByManager[manager];
|
|
@@ -227,6 +227,10 @@ async function handle(request) {
|
|
|
227
227
|
return;
|
|
228
228
|
case "notifications/initialized":
|
|
229
229
|
return;
|
|
230
|
+
// Either side may ping at any time, before or after initialization; the answer is an empty result.
|
|
231
|
+
case "ping":
|
|
232
|
+
success(id, {});
|
|
233
|
+
return;
|
|
230
234
|
case "tools/list":
|
|
231
235
|
success(id, { tools });
|
|
232
236
|
return;
|
|
@@ -91,7 +91,8 @@ export async function observe(options) {
|
|
|
91
91
|
const repoPath = resolve(options.repoPath);
|
|
92
92
|
const git = options.git ?? makeGitRunner(repoPath);
|
|
93
93
|
const ci = readCiEnvironment(options.env);
|
|
94
|
-
|
|
94
|
+
// GitLab's CI_PROJECT_PATH may name subgroups (group/sub/project): keep every segment, not the first two.
|
|
95
|
+
const ownerName = ci.ownerName && /^[^/]+(?:\/[^/]+)+$/.test(ci.ownerName) ? ci.ownerName : undefined;
|
|
95
96
|
const before = { head: headSha(git), worktree: worktreeDigest(git) };
|
|
96
97
|
const hashPath = (path) => (options.redactPaths ? redactPath(path, sha256) : path);
|
|
97
98
|
// Declared before `finish` closes over it: the range is part of every report, including the reports
|
|
@@ -124,7 +125,7 @@ export async function observe(options) {
|
|
|
124
125
|
},
|
|
125
126
|
repository: {
|
|
126
127
|
provider: ci.provider === "github-actions" ? "github" : ci.provider === "gitlab-ci" ? "gitlab" : "unknown",
|
|
127
|
-
ownerName
|
|
128
|
+
ownerName,
|
|
128
129
|
defaultBranch: ci.defaultBranch,
|
|
129
130
|
providerRepositoryId: ci.providerRepositoryId,
|
|
130
131
|
},
|
|
@@ -37,7 +37,7 @@ export interface ObservationCommitRange {
|
|
|
37
37
|
}
|
|
38
38
|
export interface ObservationRepository {
|
|
39
39
|
provider: "github" | "gitlab" | "unknown";
|
|
40
|
-
/** "owner/name". The only repository identifier sent; never a URL carrying a token. */
|
|
40
|
+
/** "owner/name", or GitLab's full "group/subgroup/name" path. The only repository identifier sent; never a URL carrying a token. */
|
|
41
41
|
ownerName?: string;
|
|
42
42
|
defaultBranch?: string;
|
|
43
43
|
/** GitHub's numeric repository id when the environment supplies it - survives a rename. */
|
|
@@ -327,14 +327,16 @@ export function configureGraphCache(input) {
|
|
|
327
327
|
if (input.shared) {
|
|
328
328
|
const baseUrl = resolveSharedGraphCacheBaseUrl({ cacheUrl: input.cacheUrl, apiUrl: input.apiUrl });
|
|
329
329
|
const secret = input.secret && input.secret.length >= 16 ? input.secret : undefined;
|
|
330
|
-
if (input.secret && !secret)
|
|
331
|
-
notes.push("DIFFCI_GRAPH_CACHE_SECRET ignored: it must be at least 16 characters");
|
|
332
330
|
if (input.noSend)
|
|
333
331
|
notes.push("shared graph cache off: --no-send");
|
|
334
332
|
else if (!baseUrl)
|
|
335
333
|
notes.push("shared graph cache off: no https api-url or graph-cache-url");
|
|
336
334
|
else if (!input.token)
|
|
337
335
|
notes.push("shared graph cache off: no api-token");
|
|
336
|
+
// A secret that is set asks for encryption: one too short to use must not fall back to plaintext uploads.
|
|
337
|
+
// An empty value counts as set: `DIFFCI_GRAPH_CACHE_SECRET: ${{ secrets.X }}` is empty when X is missing.
|
|
338
|
+
else if (input.secret !== undefined && !secret)
|
|
339
|
+
notes.push("shared graph cache off: DIFFCI_GRAPH_CACHE_SECRET must be at least 16 characters");
|
|
338
340
|
else if (input.redactPaths && !secret)
|
|
339
341
|
notes.push("shared graph cache off: --redact-paths needs DIFFCI_GRAPH_CACHE_SECRET, because the graph carries file paths");
|
|
340
342
|
else
|
|
@@ -96,7 +96,8 @@ export function repositoryName(repoPath, env) {
|
|
|
96
96
|
function surfaceOf(env) {
|
|
97
97
|
if (env.DIFFCI_MCP === "1")
|
|
98
98
|
return "local-mcp";
|
|
99
|
-
|
|
99
|
+
// Each CI wrapper sets its own value: action/, integrations/gitlab and integrations/azure-devops (#303).
|
|
100
|
+
if (env.DIFFCI_SURFACE === "github-action" || env.DIFFCI_SURFACE === "gitlab-component" || env.DIFFCI_SURFACE === "azure-devops-task")
|
|
100
101
|
return env.DIFFCI_SURFACE;
|
|
101
102
|
return "cli";
|
|
102
103
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** Best-effort usage signal. Carries a repository name only when given one; never content, paths or machine details. */
|
|
2
2
|
export type UsageCommand = "check" | "observe" | "verify" | "plan";
|
|
3
3
|
export type UsageOutcome = "observed" | "refused" | "error" | "passed" | "failed" | "blocked" | "selective" | "full";
|
|
4
|
-
export type UsageSurface = "cli" | "local-mcp" | "github-action" | "gitlab-component";
|
|
4
|
+
export type UsageSurface = "cli" | "local-mcp" | "github-action" | "gitlab-component" | "azure-devops-task";
|
|
5
5
|
export interface UsageSignal {
|
|
6
6
|
command: UsageCommand;
|
|
7
7
|
outcome: UsageOutcome;
|
|
@@ -165,6 +165,12 @@ interface ResolvedSelection {
|
|
|
165
165
|
observationSha256?: string;
|
|
166
166
|
observerVersion?: string;
|
|
167
167
|
}
|
|
168
|
+
/**
|
|
169
|
+
* At most the last `bytes` bytes of `value`, cut at a character boundary. `bytes` 0 keeps nothing:
|
|
170
|
+
* `value.slice(-0)` is the whole string, so `--tail-bytes 0` used to keep the entire output, and a
|
|
171
|
+
* multi-byte tail was cut by characters, not bytes.
|
|
172
|
+
*/
|
|
173
|
+
export declare function tail(value: string, bytes: number): string;
|
|
168
174
|
export declare function measureCommand(command: string, options: Pick<VerifySavingsOptions, "cwd" | "timeoutMs" | "tailBytes"> & {
|
|
169
175
|
env?: Record<string, string>;
|
|
170
176
|
}): CommandMeasurement;
|
|
@@ -8,10 +8,22 @@ import { windowsLaunch, withPathEntry } from "./node-bin-launch.js";
|
|
|
8
8
|
import { runnerTestCount } from "./selected-coverage.js";
|
|
9
9
|
import { parseTestFileResults } from "./test-results.js";
|
|
10
10
|
import { classifyFailureFromEvidence, computeFailureFingerprint } from "../preflight/fingerprint.js";
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
/**
|
|
12
|
+
* At most the last `bytes` bytes of `value`, cut at a character boundary. `bytes` 0 keeps nothing:
|
|
13
|
+
* `value.slice(-0)` is the whole string, so `--tail-bytes 0` used to keep the entire output, and a
|
|
14
|
+
* multi-byte tail was cut by characters, not bytes.
|
|
15
|
+
*/
|
|
16
|
+
export function tail(value, bytes) {
|
|
17
|
+
if (!(bytes > 0))
|
|
18
|
+
return "";
|
|
19
|
+
const buffer = Buffer.from(value, "utf8");
|
|
20
|
+
if (buffer.length <= bytes)
|
|
13
21
|
return value;
|
|
14
|
-
|
|
22
|
+
let start = buffer.length - Math.floor(bytes);
|
|
23
|
+
// Skip UTF-8 continuation bytes so the tail never starts inside a character.
|
|
24
|
+
while (start < buffer.length && (buffer[start] & 0xc0) === 0x80)
|
|
25
|
+
start++;
|
|
26
|
+
return buffer.subarray(start).toString("utf8");
|
|
15
27
|
}
|
|
16
28
|
function readSelectionFromObservation(path, override) {
|
|
17
29
|
const absolutePath = resolve(path);
|