@criogaid/pi-hashline-edit 0.9.0 → 0.11.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/README.md +12 -12
- package/README.zh-CN.md +12 -12
- package/THIRD_PARTY_NOTICES.md +0 -6
- package/package.json +1 -1
- package/src/core/AGENTS.md +4 -5
- package/src/core/apply.test.ts +96 -271
- package/src/core/apply.ts +62 -169
- package/src/core/case-fold.ts +8 -67
- package/src/core/character-set.test.ts +2 -3
- package/src/core/character-set.ts +5 -5
- package/src/core/errors.test.ts +23 -7
- package/src/core/errors.ts +32 -5
- package/src/core/hash.test.ts +8 -16
- package/src/core/hash.ts +3 -23
- package/src/core/lines.ts +2 -4
- package/src/core/ranges.test.ts +2 -1
- package/src/core/ranges.ts +1 -1
- package/src/core/regex.ts +3 -4
- package/src/core/replace.test.ts +47 -1
- package/src/core/replace.ts +19 -13
- package/src/core/search-analysis.test.ts +24 -27
- package/src/core/search-analysis.ts +34 -65
- package/src/core/search-matrix.testing.ts +0 -2
- package/src/core/search.ts +1 -1
- package/src/core/text.test.ts +5 -5
- package/src/core/text.ts +5 -12
- package/src/core/types.ts +8 -44
- package/src/index.ts +8 -8
- package/src/integration/config-registration.test.ts +8 -10
- package/src/integration/fusion-dispatch.test.ts +4 -7
- package/src/integration/grep-errors.test.ts +3 -3
- package/src/integration/grep-flags.test.ts +5 -19
- package/src/integration/grep-js-completeness.test.ts +45 -18
- package/src/integration/grep-line-candidates.test.ts +7 -10
- package/src/integration/grep-matrix.test.ts +6 -9
- package/src/integration/grep-order.test.ts +4 -4
- package/src/integration/grep-path-matrix.test.ts +10 -9
- package/src/integration/grep-prefilter-coverage.test.ts +5 -8
- package/src/integration/grep-process-limits.test.ts +76 -0
- package/src/integration/grep-regex.test.ts +10 -10
- package/src/integration/grep-rg.test.ts +166 -66
- package/src/integration/grep-scan-budget.test.ts +9 -9
- package/src/integration/grep-translation.test.ts +18 -32
- package/src/integration/large-text.test.ts +6 -52
- package/src/integration/model-budget-lifecycle.test.ts +10 -9
- package/src/integration/mutation-file-types.testing.ts +4 -4
- package/src/integration/npm-package.testing.ts +3 -3
- package/src/integration/publication-read-changes.test.ts +161 -83
- package/src/integration/read-changes.test.ts +4 -4
- package/src/integration/replace-worker-boundary.test.ts +22 -12
- package/src/integration/report-replay.test.ts +23 -26
- package/src/integration/utf8-errors.test.ts +4 -4
- package/src/pi/AGENTS.md +18 -17
- package/src/pi/action-fusion.test.ts +241 -353
- package/src/pi/action-fusion.testing.ts +38 -0
- package/src/pi/action-fusion.ts +150 -125
- package/src/pi/anchor-format.test.ts +9 -9
- package/src/pi/anchor-format.ts +6 -8
- package/src/pi/argument-diagnostics.ts +25 -28
- package/src/pi/argument-error.ts +2 -1
- package/src/pi/argument-format.test.ts +19 -18
- package/src/pi/argument-validation.test.ts +334 -283
- package/src/pi/argument-validation.ts +5 -8
- package/src/pi/budgets.ts +6 -8
- package/src/pi/codemode.test.ts +7 -2
- package/src/pi/config.test.ts +7 -3
- package/src/pi/config.ts +12 -9
- package/src/pi/diagnostic-buffer.test.ts +34 -13
- package/src/pi/diagnostic-buffer.ts +1 -2
- package/src/pi/directory-sync.test.ts +0 -1
- package/src/pi/edit-tool.ts +86 -211
- package/src/pi/error-text.ts +10 -9
- package/src/pi/execute.test.ts +249 -345
- package/src/pi/failure-context.test.ts +146 -127
- package/src/pi/failure-context.ts +45 -94
- package/src/pi/failure-path.test.ts +182 -155
- package/src/pi/file-commit.test.ts +156 -71
- package/src/pi/file-commit.ts +126 -146
- package/src/pi/file-snapshot.test.ts +3 -5
- package/src/pi/fusion-card.test.ts +26 -22
- package/src/pi/fusion-card.ts +16 -24
- package/src/pi/grep-candidates.test.ts +19 -120
- package/src/pi/grep-candidates.ts +25 -76
- package/src/pi/grep-matrix.test.ts +5 -5
- package/src/pi/grep-order.test.ts +16 -15
- package/src/pi/grep-output.ts +94 -107
- package/src/pi/grep-render.ts +1 -1
- package/src/pi/grep-reread.ts +97 -0
- package/src/pi/grep-rg.testing.ts +70 -0
- package/src/pi/grep-scope.ts +41 -43
- package/src/pi/grep-search.ts +27 -39
- package/src/pi/grep-tool.ts +63 -106
- package/src/pi/grep.test.ts +177 -156
- package/src/pi/model-budgets.test.ts +27 -24
- package/src/pi/model-budgets.ts +6 -38
- package/src/pi/mutation-outcome.testing.ts +0 -1
- package/src/pi/mutation-result.test.ts +44 -35
- package/src/pi/mutation-result.ts +52 -21
- package/src/pi/mutation-runner.ts +134 -74
- package/src/pi/output-budgets.test.ts +86 -42
- package/src/pi/path.ts +1 -1
- package/src/pi/pi.test.ts +18 -13
- package/src/pi/read-tool.ts +18 -23
- package/src/pi/read.test.ts +22 -41
- package/src/pi/regex-worker-contract.ts +3 -13
- package/src/pi/regex-worker.ts +1 -10
- package/src/pi/registration.test.ts +85 -51
- package/src/pi/render.test.ts +88 -59
- package/src/pi/render.ts +64 -65
- package/src/pi/replace-regex.ts +14 -2
- package/src/pi/replace-tool.ts +22 -94
- package/src/pi/replace-worker.ts +1 -1
- package/src/pi/replace.test.ts +53 -38
- package/src/pi/report-cause.ts +3 -8
- package/src/pi/report-failure.testing.ts +10 -3
- package/src/pi/report-schema.ts +251 -148
- package/src/pi/report.test.ts +215 -67
- package/src/pi/report.ts +50 -98
- package/src/pi/result-safety.test.ts +241 -247
- package/src/pi/rg-process.test.ts +77 -63
- package/src/pi/rg-process.ts +53 -75
- package/src/pi/rg-regex.ts +40 -400
- package/src/pi/schema.ts +35 -0
- package/src/pi/text-stream.test.ts +0 -21
- package/src/pi/text-stream.ts +14 -21
- package/src/pi/tool-factories.testing.ts +59 -0
- package/src/pi/write-tool.ts +36 -71
- package/src/pi/write.test.ts +31 -34
- package/src/testing/regex-translation-corpus.ts +12 -12
- package/src/testing/run-tests.ts +1 -1
- package/src/pi/replace-worker-contract.ts +0 -10
|
@@ -15,7 +15,7 @@ import type { ArgumentIssue, ReportTool } from "./report-schema.ts";
|
|
|
15
15
|
|
|
16
16
|
/** Report one semantic issue: what is wrong (a fact), and how to correct it when the fact alone does not say. */
|
|
17
17
|
export type ReportArgumentIssue = (field: string, reason: string, fix?: string) => void;
|
|
18
|
-
type CheckArguments = (args: unknown, report: ReportArgumentIssue) => void;
|
|
18
|
+
export type CheckArguments = (args: unknown, report: ReportArgumentIssue) => void;
|
|
19
19
|
|
|
20
20
|
/** Inspect arrays and the singleton objects Pi may coerce, without changing input. */
|
|
21
21
|
export function argumentItems(value: unknown): readonly unknown[] {
|
|
@@ -82,18 +82,15 @@ export function createArgumentPreparer<T extends TObject>(
|
|
|
82
82
|
check?.(checked, (field, reason, fix) =>
|
|
83
83
|
issues.push(fix === undefined ? { field, reason } : { field, reason, fix }),
|
|
84
84
|
);
|
|
85
|
+
// Keep Pi's preparation contract: the framework performs its own coercion next.
|
|
85
86
|
if (schemaFailure === undefined && issues.length === 0) return args as Static<T>;
|
|
86
87
|
const result = diagnoseArguments(parameters, checked, issues, schemaFailure !== undefined);
|
|
87
88
|
const reported =
|
|
88
89
|
result.issues.length > 0
|
|
89
90
|
? result.issues
|
|
90
91
|
: [{ field: "$", reason: errorMessage(schemaFailure) }];
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
// Keep Pi's preparation contract: the framework performs its own coercion next.
|
|
97
|
-
return args as Static<T>;
|
|
92
|
+
throw new Error(formatArgumentError(reported, result.limited, budgets()), {
|
|
93
|
+
cause: schemaFailure,
|
|
94
|
+
});
|
|
98
95
|
};
|
|
99
96
|
}
|
package/src/pi/budgets.ts
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
* The context window is a capacity hint, not a tokenizer or remaining-context counter.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
const BYTES_PER_CONTEXT_TOKEN = 1;
|
|
7
6
|
const BLOCK_SHARE = 4;
|
|
8
7
|
const FIELD_SHARE = 4;
|
|
9
8
|
const UTF16_PREVIEW_BYTES = 4;
|
|
@@ -16,6 +15,7 @@ const MIN_FIELD_BYTES = 128;
|
|
|
16
15
|
export const MAX_CONTENT_KIB = 4096;
|
|
17
16
|
const MAX_CONTENT_BYTES = MAX_CONTENT_KIB * 1024;
|
|
18
17
|
|
|
18
|
+
// Declared apart so Object.freeze keeps these as numbers rather than literal types.
|
|
19
19
|
const fallbackBudgets = {
|
|
20
20
|
readBytes: 256 * 1024,
|
|
21
21
|
grepBytes: 50 * 1024,
|
|
@@ -23,7 +23,7 @@ const fallbackBudgets = {
|
|
|
23
23
|
fieldBytes: 4 * 1024,
|
|
24
24
|
grepPreviewUnits: 500,
|
|
25
25
|
};
|
|
26
|
-
|
|
26
|
+
const DEFAULT_OUTPUT_BUDGETS = Object.freeze(fallbackBudgets);
|
|
27
27
|
export type OutputBudgets = typeof DEFAULT_OUTPUT_BUDGETS;
|
|
28
28
|
export type OutputBudgetProvider = () => OutputBudgets;
|
|
29
29
|
|
|
@@ -32,7 +32,8 @@ export function outputBudgetsFor(contextWindow: number | undefined): OutputBudge
|
|
|
32
32
|
if (contextWindow === undefined || !Number.isSafeInteger(contextWindow) || contextWindow <= 0) {
|
|
33
33
|
return DEFAULT_OUTPUT_BUDGETS;
|
|
34
34
|
}
|
|
35
|
-
|
|
35
|
+
// One byte per declared context token.
|
|
36
|
+
const contentBytes = Math.min(contextWindow, MAX_CONTENT_BYTES);
|
|
36
37
|
const blockBytes = Math.max(MIN_BLOCK_BYTES, Math.floor(contentBytes / BLOCK_SHARE));
|
|
37
38
|
const fieldBytes = Math.max(MIN_FIELD_BYTES, Math.floor(blockBytes / FIELD_SHARE));
|
|
38
39
|
return Object.freeze({
|
|
@@ -44,12 +45,9 @@ export function outputBudgetsFor(contextWindow: number | undefined): OutputBudge
|
|
|
44
45
|
});
|
|
45
46
|
}
|
|
46
47
|
|
|
47
|
-
/** Standalone tool factories have no session model until a provider is supplied. */
|
|
48
|
-
export const defaultOutputBudgets: OutputBudgetProvider = () => DEFAULT_OUTPUT_BUDGETS;
|
|
49
|
-
|
|
50
48
|
const MIB = 1024 * 1024;
|
|
51
49
|
|
|
52
|
-
/** Size wording for every model-facing limit: whole MiB as `256 MiB`, otherwise `
|
|
50
|
+
/** Size wording for every model-facing limit: whole MiB as `256 MiB`, otherwise `195.3 KiB`. */
|
|
53
51
|
export function formatByteSize(bytes: number): string {
|
|
54
|
-
return bytes % MIB === 0 ? `${bytes / MIB} MiB` : `${bytes / 1024} KiB`;
|
|
52
|
+
return bytes % MIB === 0 ? `${bytes / MIB} MiB` : `${Number((bytes / 1024).toFixed(1))} KiB`;
|
|
55
53
|
}
|
package/src/pi/codemode.test.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { Type } from "typebox";
|
|
|
6
6
|
import { createCodemodeToolDefinition } from "../../node_modules/@earendil-works/pi-coding-agent/dist/extensions/codemode/tool.js";
|
|
7
7
|
import { openTestSession, responseStream, SESSION_TIMEOUT_MS } from "../testing/session.testing.ts";
|
|
8
8
|
import { createActionFusionExecutor } from "./action-fusion.ts";
|
|
9
|
-
import { makeWriteOverride } from "./
|
|
9
|
+
import { makeWriteOverride } from "./tool-factories.testing.ts";
|
|
10
10
|
|
|
11
11
|
for (const entry of ["direct", "codemode"] as const) {
|
|
12
12
|
test(`${entry} mutation waits on then_run → the call and model continuation stay pending`, {
|
|
@@ -17,7 +17,12 @@ for (const entry of ["direct", "codemode"] as const) {
|
|
|
17
17
|
const { cwd, session, model } = await openTestSession(t, {
|
|
18
18
|
tools: ["write", "bash", "codemode"],
|
|
19
19
|
configure(pi, cwd) {
|
|
20
|
-
pi.registerTool(
|
|
20
|
+
pi.registerTool(
|
|
21
|
+
makeWriteOverride(
|
|
22
|
+
cwd,
|
|
23
|
+
createActionFusionExecutor(() => {}),
|
|
24
|
+
),
|
|
25
|
+
);
|
|
21
26
|
pi.registerTool(createCodemodeToolDefinition());
|
|
22
27
|
pi.registerTool({
|
|
23
28
|
name: "bash",
|
package/src/pi/config.test.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { DEFAULT_MAX_LINES } from "@earendil-works/pi-coding-agent";
|
|
1
2
|
import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
2
3
|
import { tmpdir } from "node:os";
|
|
3
4
|
import { join } from "node:path";
|
|
4
5
|
import assert from "node:assert/strict";
|
|
5
6
|
import { test } from "node:test";
|
|
6
|
-
import {
|
|
7
|
+
import { loadConfig } from "./config.ts";
|
|
8
|
+
import { DEFAULT_CONFIG } from "./tool-factories.testing.ts";
|
|
7
9
|
|
|
8
10
|
async function withSettings(
|
|
9
11
|
fn: (
|
|
@@ -34,7 +36,7 @@ test("defaults come from the settings schema", () => {
|
|
|
34
36
|
actionFusion: true,
|
|
35
37
|
hashLen: 4,
|
|
36
38
|
shiftRadius: 15,
|
|
37
|
-
read: { defaultLimit:
|
|
39
|
+
read: { defaultLimit: DEFAULT_MAX_LINES, maxKiB: undefined },
|
|
38
40
|
grep: { ...DEFAULT_CONFIG.grep, defaultLimit: 100, defaultContext: 0 },
|
|
39
41
|
replace: { regexTimeoutMs: 5_000 },
|
|
40
42
|
});
|
|
@@ -114,7 +116,9 @@ test("project settings replace global groups while absent project settings use g
|
|
|
114
116
|
join(agentDir, "settings.json"),
|
|
115
117
|
JSON.stringify({ hashlineEdit: globalConfig }),
|
|
116
118
|
);
|
|
117
|
-
|
|
119
|
+
const withoutSettings = join(root, "without-settings");
|
|
120
|
+
await mkdir(withoutSettings);
|
|
121
|
+
assert.deepEqual(loadConfig(withoutSettings), globalConfig);
|
|
118
122
|
assert.deepEqual(loadConfig(root), globalConfig);
|
|
119
123
|
for (const settings of [{}, null, [], 42, "settings"]) {
|
|
120
124
|
await write(settings);
|
package/src/pi/config.ts
CHANGED
|
@@ -6,14 +6,14 @@
|
|
|
6
6
|
* @module pi-hashline-edit/pi
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { getAgentDir } from "@earendil-works/pi-coding-agent";
|
|
9
|
+
import { DEFAULT_MAX_LINES, getAgentDir } from "@earendil-works/pi-coding-agent";
|
|
10
10
|
import * as fs from "node:fs";
|
|
11
11
|
import * as path from "node:path";
|
|
12
12
|
import { Type, type Static, type TSchema } from "typebox";
|
|
13
13
|
import { Value } from "typebox/value";
|
|
14
14
|
import { HASH_LEN_MAX, HASH_LEN_MIN } from "../core/hash.ts";
|
|
15
15
|
import { GREP_CONTEXT_RANGE, integerRange, POSITIVE_SAFE_INTEGER } from "./schema.ts";
|
|
16
|
-
import { MAX_CONTENT_KIB } from "./budgets.ts";
|
|
16
|
+
import { MAX_CONTENT_KIB, type OutputBudgetProvider } from "./budgets.ts";
|
|
17
17
|
|
|
18
18
|
function integerSetting(
|
|
19
19
|
range: ReturnType<typeof integerRange>,
|
|
@@ -24,7 +24,6 @@ function integerSetting(
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
// The floor exceeds measured worker startup+handshake on slower Windows hosts.
|
|
27
|
-
// README's regex timeout settings link to this shared definition.
|
|
28
27
|
const regexTimeoutSetting = integerSetting(
|
|
29
28
|
integerRange(3_000, 300_000),
|
|
30
29
|
5_000,
|
|
@@ -55,7 +54,7 @@ const configSchema = Type.Object({
|
|
|
55
54
|
read: Type.Object({
|
|
56
55
|
defaultLimit: integerSetting(
|
|
57
56
|
POSITIVE_SAFE_INTEGER,
|
|
58
|
-
|
|
57
|
+
DEFAULT_MAX_LINES,
|
|
59
58
|
"Lines returned when limit is omitted.",
|
|
60
59
|
),
|
|
61
60
|
maxKiB: Type.Optional(
|
|
@@ -86,6 +85,13 @@ const configSchema = Type.Object({
|
|
|
86
85
|
|
|
87
86
|
export type HashlineEditConfig = Static<typeof configSchema>;
|
|
88
87
|
|
|
88
|
+
/** What a tool captures at registration and keeps for its lifetime. */
|
|
89
|
+
export interface ToolEnvironment {
|
|
90
|
+
readonly cwd: string;
|
|
91
|
+
readonly config: HashlineEditConfig;
|
|
92
|
+
readonly budgets: OutputBudgetProvider;
|
|
93
|
+
}
|
|
94
|
+
|
|
89
95
|
function asRecord(value: unknown): Record<string, unknown> {
|
|
90
96
|
return value !== null && typeof value === "object" && !Array.isArray(value)
|
|
91
97
|
? (value as Record<string, unknown>)
|
|
@@ -108,12 +114,9 @@ function resolveSetting<T extends TSchema>(schema: T, value: unknown): Static<T>
|
|
|
108
114
|
) as Static<T>;
|
|
109
115
|
}
|
|
110
116
|
|
|
111
|
-
export const DEFAULT_CONFIG: HashlineEditConfig = resolveSetting(configSchema, {});
|
|
112
|
-
|
|
113
117
|
/** Parse JSON directly without stripping comments (standard JSON forbids comments; on error fall back to default). */
|
|
114
118
|
function readSettings(filePath: string): Record<string, unknown> {
|
|
115
119
|
try {
|
|
116
|
-
if (!fs.existsSync(filePath)) return {};
|
|
117
120
|
return asRecord(JSON.parse(fs.readFileSync(filePath, "utf-8")));
|
|
118
121
|
} catch {
|
|
119
122
|
return {};
|
|
@@ -124,9 +127,9 @@ function readSettings(filePath: string): Record<string, unknown> {
|
|
|
124
127
|
* Load config. The `hashlineEdit` in project `cwd/.pi/settings.json` replaces
|
|
125
128
|
* the global one wholesale; missing or invalid settings use their defaults.
|
|
126
129
|
*/
|
|
127
|
-
export function loadConfig(cwd
|
|
130
|
+
export function loadConfig(cwd: string): HashlineEditConfig {
|
|
128
131
|
const globalSettings = readSettings(path.join(getAgentDir(), "settings.json"));
|
|
129
|
-
const projectSettings =
|
|
132
|
+
const projectSettings = readSettings(path.join(cwd, ".pi", "settings.json"));
|
|
130
133
|
// Any project value replaces the global one, even null or an invalid value, which yields defaults.
|
|
131
134
|
const settings = Object.hasOwn(projectSettings, "hashlineEdit")
|
|
132
135
|
? projectSettings
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import assert from "node:assert/strict";
|
|
2
2
|
import { test } from "node:test";
|
|
3
|
+
import childProcess from "node:child_process";
|
|
4
|
+
import { syncBuiltinESMExports } from "node:module";
|
|
3
5
|
import { DiagnosticBuffer } from "./diagnostic-buffer.ts";
|
|
4
|
-
import { DEFAULT_OUTPUT_BUDGETS } from "./
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
6
|
+
import { DEFAULT_OUTPUT_BUDGETS } from "./tool-factories.testing.ts";
|
|
7
|
+
import { grepOutput } from "./grep-output.ts";
|
|
8
|
+
import { createAnchorFormatter } from "./anchor-format.ts";
|
|
9
|
+
import { runRgPaths } from "./rg-process.ts";
|
|
10
|
+
const MAX_RG_STDERR_BYTES = 64 * 1024;
|
|
7
11
|
import { mkdtemp, writeFile, rm } from "node:fs/promises";
|
|
8
12
|
import { tmpdir } from "node:os";
|
|
9
13
|
import { join } from "node:path";
|
|
@@ -44,18 +48,27 @@ test("diagnostics within the budget are unchanged", () => {
|
|
|
44
48
|
assert.equal(buffer.toString(), source);
|
|
45
49
|
});
|
|
46
50
|
|
|
47
|
-
test("search warning aggregation retains the final cause and labels truncation", () => {
|
|
48
|
-
const { facts, payload } =
|
|
51
|
+
test("search warning aggregation retains the final cause and labels truncation", async () => {
|
|
52
|
+
const { facts, payload } = await grepOutput({
|
|
49
53
|
budget: DEFAULT_OUTPUT_BUDGETS,
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
+
cwd: process.cwd(),
|
|
55
|
+
anchors: createAnchorFormatter(4),
|
|
56
|
+
context: 0,
|
|
57
|
+
search: {
|
|
58
|
+
files: [
|
|
59
|
+
{
|
|
60
|
+
filePath: join(process.cwd(), "confirmed match"),
|
|
61
|
+
rows: [],
|
|
62
|
+
snapshot: { revision: "", validUtf8: true },
|
|
63
|
+
},
|
|
64
|
+
],
|
|
65
|
+
matchLimitReached: false,
|
|
66
|
+
scanLimitReached: false,
|
|
54
67
|
},
|
|
55
|
-
warnings: [diagnostic(DEFAULT_OUTPUT_BUDGETS.fieldBytes)],
|
|
56
|
-
outputMode: "
|
|
57
|
-
matchLimitReached: false,
|
|
68
|
+
warnings: [{ reason: diagnostic(DEFAULT_OUTPUT_BUDGETS.fieldBytes) }],
|
|
69
|
+
outputMode: "files",
|
|
58
70
|
effectiveLimit: 100,
|
|
71
|
+
literalPipe: false,
|
|
59
72
|
});
|
|
60
73
|
assert.equal(payload, "confirmed match");
|
|
61
74
|
assert.match(facts.diagnostics ?? "", /regex parse error:/);
|
|
@@ -64,13 +77,21 @@ test("search warning aggregation retains the final cause and labels truncation",
|
|
|
64
77
|
});
|
|
65
78
|
|
|
66
79
|
test("stderr overflow → UTF-8 opening and final cause survive", async (t) => {
|
|
80
|
+
const spawn = childProcess.spawn;
|
|
81
|
+
t.mock.method(childProcess, "spawn", (...args: Parameters<typeof spawn>) =>
|
|
82
|
+
spawn(process.execPath, args[1] ?? [], args[2]),
|
|
83
|
+
);
|
|
84
|
+
syncBuiltinESMExports();
|
|
85
|
+
t.after(() => {
|
|
86
|
+
t.mock.restoreAll();
|
|
87
|
+
syncBuiltinESMExports();
|
|
88
|
+
});
|
|
67
89
|
const directory = await mkdtemp(join(tmpdir(), "hl-rg-stderr-"));
|
|
68
90
|
t.after(() => rm(directory, { recursive: true, force: true }));
|
|
69
91
|
const path = join(directory, "stderr.txt");
|
|
70
92
|
for (const source of ["权限不足🙂\n", diagnostic(MAX_RG_STDERR_BYTES)]) {
|
|
71
93
|
await writeFile(path, source);
|
|
72
94
|
const result = await runRgPaths(
|
|
73
|
-
process.execPath,
|
|
74
95
|
[
|
|
75
96
|
"--input-type=module",
|
|
76
97
|
"--eval",
|
|
@@ -17,12 +17,11 @@ export class DiagnosticBuffer {
|
|
|
17
17
|
private head = "";
|
|
18
18
|
private tail = "";
|
|
19
19
|
private truncated = false;
|
|
20
|
+
private readonly maxBytes: number;
|
|
20
21
|
private readonly notice: string;
|
|
21
22
|
private readonly headBytes: number;
|
|
22
23
|
private readonly tailBytes: number;
|
|
23
24
|
|
|
24
|
-
private readonly maxBytes: number;
|
|
25
|
-
|
|
26
25
|
constructor(maxBytes: number) {
|
|
27
26
|
this.maxBytes = maxBytes;
|
|
28
27
|
this.notice = `\n[Diagnostics truncated (${formatByteSize(maxBytes)} limit); middle omitted.]\n`;
|
|
@@ -37,7 +37,6 @@ test("macOS attempts directory sync, tolerates unsupported operations, and prese
|
|
|
37
37
|
(error: unknown) =>
|
|
38
38
|
error instanceof FileMutationError &&
|
|
39
39
|
error.publication === "PUBLISHED" &&
|
|
40
|
-
error.stage === "post_process" &&
|
|
41
40
|
error.cause instanceof Error &&
|
|
42
41
|
"code" in error.cause &&
|
|
43
42
|
error.cause.code === "EIO",
|