Skip to content

Commit 162e8d1

Browse files
authored
refactor(plugins): derive private config types from schemas (#130414)
* refactor(plugins): derive private config types from schemas * test(ci): make directory binding proof deterministic Replace race-prone child-cwd polling with a synchronous fixture retarget after the real chdir, preserving the full worker and security assertions. Shrink the assertion-safety baseline for the three casts removed by the schema cleanup.
1 parent fc6cf5e commit 162e8d1

5 files changed

Lines changed: 40 additions & 94 deletions

File tree

‎config/assertion-safety-baseline.txt‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ extensions/diagnostics-otel/src/service-propagation.ts 2
313313
extensions/diagnostics-otel/src/service-trace-context.ts 1
314314
extensions/diagnostics-otel/src/service.ts 1
315315
extensions/diagnostics-prometheus/src/service.ts 1
316-
extensions/diffs/src/config.ts 5
316+
extensions/diffs/src/config.ts 4
317317
extensions/diffs/src/language-hints.ts 9
318318
extensions/diffs/src/plugin.ts 4
319319
extensions/diffs/src/store.ts 3
@@ -875,7 +875,6 @@ extensions/msteams/src/sqlite-state.ts 1
875875
extensions/msteams/src/sso-token-store.ts 2
876876
extensions/msteams/src/token-response.ts 2
877877
extensions/msteams/src/user-agent.ts 1
878-
extensions/mxc/src/config.ts 1
879878
extensions/mxc/src/fs-bridge.ts 1
880879
extensions/nextcloud-talk/src/approval-auth.ts 1
881880
extensions/nextcloud-talk/src/channel.ts 2
@@ -958,7 +957,6 @@ extensions/openrouter/usage.ts 2
958957
extensions/openrouter/video-generation-provider.ts 1
959958
extensions/openrouter/video-model-catalog.ts 1
960959
extensions/openshell/src/backend.ts 2
961-
extensions/openshell/src/config.ts 1
962960
extensions/openshell/src/fs-bridge.ts 2
963961
extensions/parallel/src/parallel-free-web-search-provider.runtime.ts 1
964962
extensions/parallel/src/parallel-search-normalize.ts 1

‎extensions/diffs/src/config.ts‎

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -21,39 +21,7 @@ import {
2121
} from "./types.js";
2222
import { normalizeViewerBaseUrl } from "./url.js";
2323

24-
type DiffsPluginConfig = {
25-
viewerBaseUrl?: string;
26-
defaults?: {
27-
fontFamily?: string;
28-
fontSize?: number;
29-
lineSpacing?: number;
30-
layout?: DiffLayout;
31-
showLineNumbers?: boolean;
32-
diffIndicators?: DiffIndicators;
33-
wordWrap?: boolean;
34-
background?: boolean;
35-
theme?: DiffTheme;
36-
fileFormat?: DiffOutputFormat;
37-
fileQuality?: DiffImageQualityPreset;
38-
fileScale?: number;
39-
fileMaxWidth?: number;
40-
/** @deprecated Use fileFormat. */
41-
format?: DiffOutputFormat;
42-
/** @deprecated Use fileFormat. */
43-
imageFormat?: DiffOutputFormat;
44-
/** @deprecated Use fileQuality. */
45-
imageQuality?: DiffImageQualityPreset;
46-
/** @deprecated Use fileScale. */
47-
imageScale?: number;
48-
/** @deprecated Use fileMaxWidth. */
49-
imageMaxWidth?: number;
50-
mode?: DiffMode;
51-
ttlSeconds?: number;
52-
};
53-
security?: {
54-
allowRemoteViewer?: boolean;
55-
};
56-
};
24+
type DiffsPluginConfig = z.input<typeof DiffsPluginJsonSchemaSource>;
5725

5826
const DEFAULT_IMAGE_QUALITY_PROFILES = {
5927
standard: {
@@ -192,7 +160,7 @@ const diffsPluginConfigSchemaBase = buildPluginConfigSchema(DiffsPluginJsonSchem
192160
if (result.success) {
193161
return {
194162
success: true,
195-
data: buildDiffsPluginConfigShape(result.data as DiffsPluginConfig),
163+
data: buildDiffsPluginConfigShape(result.data),
196164
};
197165
}
198166
return {

‎extensions/file-transfer/src/node-host/dir-list.test.ts‎

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,6 @@ describe("handleDirList — happy path", () => {
6767
await fs.mkdir(replacement);
6868
await fs.writeFile(path.join(approved, "approved.txt"), "approved");
6969
await fs.writeFile(path.join(replacement, "secret.txt"), "secret");
70-
await Promise.all(
71-
Array.from({ length: 5000 }, (_, index) =>
72-
fs.writeFile(path.join(approved, `f-${String(index).padStart(4, "0")}`), ""),
73-
),
74-
);
7570
await fs.symlink(approved, current);
7671
const approvedStats = await fs.stat(approved, { bigint: true });
7772

@@ -80,40 +75,50 @@ describe("handleDirList — happy path", () => {
8075
expectedCanonicalPath: approved,
8176
expectedDevice: String(approvedStats.dev),
8277
expectedInode: String(approvedStats.ino),
83-
maxEntries: 5001,
78+
maxEntries: 10,
8479
offset: 0,
8580
});
86-
const child = spawn(command[0]!, command.slice(1), {
87-
stdio: ["ignore", "pipe", "pipe"],
88-
});
81+
// Retarget after the real chdir, before the unchanged worker checks and
82+
// enumerates its bound directory. Polling /proc can miss the entire child.
83+
const retargetAfterBinding = `(() => {
84+
const fs = require("node:fs");
85+
const chdir = process.chdir;
86+
process.chdir = (directory) => {
87+
chdir(directory);
88+
process.chdir = chdir;
89+
fs.unlinkSync(${JSON.stringify(current)});
90+
fs.symlinkSync(${JSON.stringify(replacement)}, ${JSON.stringify(current)});
91+
};
92+
})();`;
93+
const child = spawn(
94+
command[0]!,
95+
[command[1]!, retargetAfterBinding + command[2]!, ...command.slice(3)],
96+
{
97+
stdio: ["ignore", "pipe", "pipe"],
98+
},
99+
);
89100
const stdout: Buffer[] = [];
101+
const stderr: Buffer[] = [];
90102
child.stdout.on("data", (chunk: Buffer) => stdout.push(chunk));
103+
child.stderr.on("data", (chunk: Buffer) => stderr.push(chunk));
91104
const exit = new Promise<number | null>((resolve, reject) => {
92105
child.once("error", reject);
93-
child.once("exit", resolve);
106+
child.once("close", resolve);
94107
});
95-
96-
let observedBoundCwd = false;
97-
for (let attempt = 0; attempt < 200 && child.exitCode === null; attempt += 1) {
98-
const cwd = await fs.readlink(`/proc/${child.pid}/cwd`).catch(() => "");
99-
if (cwd === approved) {
100-
observedBoundCwd = true;
101-
break;
108+
try {
109+
expect(await exit, Buffer.concat(stderr).toString("utf8")).toBe(0);
110+
expect(await fs.readlink(current)).toBe(replacement);
111+
const result = JSON.parse(Buffer.concat(stdout).toString("utf8")) as {
112+
entries: Array<{ name: string }>;
113+
};
114+
expect(result.entries.some((entry) => entry.name === "approved.txt")).toBe(true);
115+
expect(result.entries.some((entry) => entry.name === "secret.txt")).toBe(false);
116+
} finally {
117+
if (child.exitCode === null && child.signalCode === null) {
118+
child.kill("SIGKILL");
102119
}
103-
await new Promise<void>((resolve) => {
104-
setTimeout(resolve, 1);
105-
});
120+
await exit.catch(() => undefined);
106121
}
107-
expect(observedBoundCwd).toBe(true);
108-
await fs.unlink(current);
109-
await fs.symlink(replacement, current);
110-
111-
expect(await exit).toBe(0);
112-
const result = JSON.parse(Buffer.concat(stdout).toString("utf8")) as {
113-
entries: Array<{ name: string }>;
114-
};
115-
expect(result.entries.some((entry) => entry.name === "approved.txt")).toBe(true);
116-
expect(result.entries.some((entry) => entry.name === "secret.txt")).toBe(false);
117122
},
118123
);
119124

‎extensions/mxc/src/config.ts‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,6 @@ type MxcContainment = (typeof MXC_CONTAINMENTS)[number];
1414

1515
type MxcNetworkMode = (typeof MXC_NETWORK_MODES)[number];
1616

17-
type MxcPluginConfig = {
18-
mxcBinaryPath?: string;
19-
containment?: MxcContainment;
20-
network?: MxcNetworkMode;
21-
timeoutSeconds?: number;
22-
debug?: boolean;
23-
mxcPolicyPaths?: string[];
24-
};
25-
2617
export type MxcConfig = {
2718
mxcBinaryPath?: string;
2819
containment: MxcContainment;
@@ -126,7 +117,7 @@ export function resolveConfig(value: unknown): MxcConfig {
126117
throw new Error(`Invalid mxc plugin config: ${message}`);
127118
}
128119

129-
const config = parsed.data as MxcPluginConfig;
120+
const config = parsed.data;
130121
const resolved: MxcConfig = {
131122
mxcBinaryPath: config.mxcBinaryPath,
132123
containment: config.containment ?? DEFAULT_CONTAINMENT,

‎extensions/openshell/src/config.ts‎

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,6 @@ import {
88
import { MAX_TIMER_TIMEOUT_SECONDS } from "openclaw/plugin-sdk/number-runtime";
99
import { z } from "zod";
1010

11-
type OpenShellPluginConfig = {
12-
mode?: "mirror" | "remote";
13-
command?: string;
14-
gateway?: string;
15-
gatewayEndpoint?: string;
16-
workspace?: string;
17-
from?: string;
18-
policy?: string;
19-
providers?: string[];
20-
gpu?: boolean;
21-
autoProviders?: boolean;
22-
remoteWorkspaceDir?: string;
23-
remoteAgentWorkspaceDir?: string;
24-
timeoutSeconds?: number;
25-
};
26-
2711
export type ResolvedOpenShellPluginConfig = {
2812
mode: "mirror" | "remote";
2913
command: string;
@@ -193,7 +177,7 @@ export function resolveOpenShellPluginConfig(value: unknown): ResolvedOpenShellP
193177
const message = formatPluginConfigIssue(parsed.error.issues[0]);
194178
throw new Error(`Invalid openshell plugin config: ${message}`);
195179
}
196-
const cfg = parsed.data as OpenShellPluginConfig;
180+
const cfg = parsed.data;
197181
const mode = cfg.mode ?? DEFAULT_MODE;
198182
return {
199183
mode,

0 commit comments

Comments
 (0)