Skip to content

Commit c331f16

Browse files
committed
refactor(migrate-hermes): consolidate test fixtures
1 parent 82540ad commit c331f16

2 files changed

Lines changed: 126 additions & 359 deletions

File tree

‎extensions/migrate-hermes/config.test.ts‎

Lines changed: 33 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,24 @@ function modelProviderValues(
2626
);
2727
}
2828

29+
async function makeHermesPaths(sourceName = "hermes") {
30+
const root = await makeTempRoot();
31+
return {
32+
root,
33+
source: path.join(root, sourceName),
34+
workspaceDir: path.join(root, "workspace"),
35+
stateDir: path.join(root, "state"),
36+
};
37+
}
38+
2939
describe("Hermes migration config mapping", () => {
3040
afterEach(async () => {
3141
vi.unstubAllEnvs();
3242
await cleanupTempRoots();
3343
});
3444

3545
it("plans provider, MCP, skill, and memory plugin config as plugin-owned items", async () => {
36-
const root = await makeTempRoot();
37-
const source = path.join(root, "hermes");
38-
const workspaceDir = path.join(root, "workspace");
39-
const stateDir = path.join(root, "state");
46+
const { source, workspaceDir, stateDir } = await makeHermesPaths();
4047
await writeFile(
4148
path.join(source, "config.yaml"),
4249
[
@@ -135,10 +142,7 @@ describe("Hermes migration config mapping", () => {
135142
});
136143

137144
it("applies mapped config items through the migration runtime config writer", async () => {
138-
const root = await makeTempRoot();
139-
const source = path.join(root, "hermes");
140-
const workspaceDir = path.join(root, "workspace");
141-
const stateDir = path.join(root, "state");
145+
const { source, workspaceDir, stateDir } = await makeHermesPaths();
142146
const config = {
143147
agents: { defaults: { workspace: workspaceDir } },
144148
} as OpenClawConfig;
@@ -188,10 +192,7 @@ describe("Hermes migration config mapping", () => {
188192
});
189193

190194
it("drops prototype-bearing provider, MCP, and skill keys during apply", async () => {
191-
const root = await makeTempRoot();
192-
const source = path.join(root, "hermes");
193-
const workspaceDir = path.join(root, "workspace");
194-
const stateDir = path.join(root, "state");
195+
const { source, workspaceDir, stateDir } = await makeHermesPaths();
195196
const config = {
196197
agents: { defaults: { workspace: workspaceDir } },
197198
} as OpenClawConfig;
@@ -240,10 +241,7 @@ describe("Hermes migration config mapping", () => {
240241
});
241242

242243
it("uses the provider runtime for CLI-applied config items", async () => {
243-
const root = await makeTempRoot();
244-
const source = path.join(root, "hermes");
245-
const workspaceDir = path.join(root, "workspace");
246-
const stateDir = path.join(root, "state");
244+
const { source, workspaceDir, stateDir } = await makeHermesPaths();
247245
const config: Record<string, unknown> = {
248246
agents: { defaults: { workspace: workspaceDir } },
249247
};
@@ -273,10 +271,7 @@ describe("Hermes migration config mapping", () => {
273271
});
274272

275273
it("omits MCP credentials without explicit secret consent", async () => {
276-
const root = await makeTempRoot();
277-
const source = path.join(root, "hermes");
278-
const workspaceDir = path.join(root, "workspace");
279-
const stateDir = path.join(root, "state");
274+
const { source, workspaceDir, stateDir } = await makeHermesPaths();
280275
const config: Record<string, unknown> = {};
281276
const envKey = ["TO", "KEN"].join("");
282277
await writeFile(
@@ -295,10 +290,7 @@ describe("Hermes migration config mapping", () => {
295290
});
296291

297292
it("translates current Hermes model-scoped providers and MCP semantics", async () => {
298-
const root = await makeTempRoot();
299-
const source = path.join(root, "hermes");
300-
const workspaceDir = path.join(root, "workspace");
301-
const stateDir = path.join(root, "state");
293+
const { source, workspaceDir, stateDir } = await makeHermesPaths();
302294
const tlsFieldName = ["client", "cert"].join("_");
303295
const tlsPaths = ["placeholder", "placeholder"];
304296
const oauthConfig = {
@@ -423,8 +415,7 @@ describe("Hermes migration config mapping", () => {
423415
});
424416

425417
it("resolves provider endpoint refs and preserves supported request options", async () => {
426-
const root = await makeTempRoot();
427-
const source = path.join(root, "hermes");
418+
const { root, source } = await makeHermesPaths();
428419
const endpointEnv = ["ACME", "BASE", "URL"].join("_");
429420
const headerEnv = ["ACME", "HEADER"].join("_");
430421
await writeFile(
@@ -504,8 +495,7 @@ describe("Hermes migration config mapping", () => {
504495
});
505496

506497
it("reports unresolved provider endpoint environment references", async () => {
507-
const root = await makeTempRoot();
508-
const source = path.join(root, "hermes");
498+
const { root, source } = await makeHermesPaths();
509499
await writeFile(
510500
path.join(source, "config.yaml"),
511501
"providers:\n acme:\n api: ${MISSING_ACME_URL}\n models: [acme-one]\n",
@@ -524,8 +514,7 @@ describe("Hermes migration config mapping", () => {
524514
});
525515

526516
it("infers Hermes provider protocols from provider and endpoint contracts", async () => {
527-
const root = await makeTempRoot();
528-
const source = path.join(root, "hermes");
517+
const { root, source } = await makeHermesPaths();
529518
await writeFile(
530519
path.join(source, "config.yaml"),
531520
[
@@ -574,8 +563,7 @@ describe("Hermes migration config mapping", () => {
574563
});
575564

576565
it("matches Hermes transport precedence for named and plain custom providers", async () => {
577-
const root = await makeTempRoot();
578-
const source = path.join(root, "hermes");
566+
const { root, source } = await makeHermesPaths();
579567
await writeFile(
580568
path.join(source, "config.yaml"),
581569
[
@@ -608,8 +596,7 @@ describe("Hermes migration config mapping", () => {
608596
});
609597

610598
it("keeps built-in Hermes provider overrides on OpenClaw's canonical provider IDs", async () => {
611-
const root = await makeTempRoot();
612-
const source = path.join(root, "hermes");
599+
const { root, source } = await makeHermesPaths();
613600
await writeFile(
614601
path.join(source, "config.yaml"),
615602
[
@@ -660,9 +647,7 @@ describe("Hermes migration config mapping", () => {
660647
});
661648

662649
it("isolates model provider conflicts", async () => {
663-
const root = await makeTempRoot();
664-
const source = path.join(root, "hermes");
665-
const workspaceDir = path.join(root, "workspace");
650+
const { root, source, workspaceDir } = await makeHermesPaths();
666651
await writeFile(
667652
path.join(source, "config.yaml"),
668653
[
@@ -749,8 +734,7 @@ describe("Hermes migration config mapping", () => {
749734
])(
750735
"imports $envName as the selected $sourceProvider endpoint",
751736
async ({ sourceProvider, envName, envValue, targetProvider, expectedApi, expectedBaseUrl }) => {
752-
const root = await makeTempRoot();
753-
const source = path.join(root, "hermes");
737+
const { root, source } = await makeHermesPaths();
754738
await writeFile(
755739
path.join(source, "config.yaml"),
756740
["model:", ` provider: ${sourceProvider}`, " default: imported-model", ""].join("\n"),
@@ -779,8 +763,7 @@ describe("Hermes migration config mapping", () => {
779763
);
780764

781765
it("preserves the standard Alibaba endpoint instead of the coding-plan default", async () => {
782-
const root = await makeTempRoot();
783-
const source = path.join(root, "hermes");
766+
const { root, source } = await makeHermesPaths();
784767
await writeFile(
785768
path.join(source, "config.yaml"),
786769
"model:\n provider: alibaba\n default: qwen-plus\n",
@@ -801,8 +784,7 @@ describe("Hermes migration config mapping", () => {
801784
});
802785

803786
it("resolves MCP environment references with source dotenv precedence and secret consent", async () => {
804-
const root = await makeTempRoot();
805-
const source = path.join(root, "hermes");
787+
const { root, source } = await makeHermesPaths();
806788
const mcpEnvName = ["MCP", "VALUE"].join("_");
807789
const mcpUrlName = ["MCP", "URL"].join("_");
808790
const dottedEnvName = ["mcp", "value"].join(".");
@@ -885,8 +867,7 @@ describe("Hermes migration config mapping", () => {
885867
});
886868

887869
it("imports a model-scoped endpoint even when Hermes names a built-in provider", async () => {
888-
const root = await makeTempRoot();
889-
const source = path.join(root, "hermes");
870+
const { root, source } = await makeHermesPaths();
890871
await writeFile(
891872
path.join(source, "config.yaml"),
892873
[
@@ -924,8 +905,7 @@ describe("Hermes migration config mapping", () => {
924905
});
925906

926907
it("preserves an explicit Hermes provider name before applying built-in aliases", async () => {
927-
const root = await makeTempRoot();
928-
const source = path.join(root, "hermes");
908+
const { root, source } = await makeHermesPaths();
929909
await writeFile(
930910
path.join(source, "config.yaml"),
931911
[
@@ -956,8 +936,7 @@ describe("Hermes migration config mapping", () => {
956936
});
957937

958938
it("keeps current providers entries ahead of matching legacy custom providers", async () => {
959-
const root = await makeTempRoot();
960-
const source = path.join(root, "hermes");
939+
const { root, source } = await makeHermesPaths();
961940
const envVar = ["CURRENT", "ACME", "TOKEN"].join("_");
962941
const legacyEnvVar = ["LEGACY", "ACME", "TOKEN"].join("_");
963942
await writeFile(
@@ -1011,8 +990,7 @@ describe("Hermes migration config mapping", () => {
1011990
});
1012991

1013992
it("does not let a custom entry shadow a canonical Hermes provider", async () => {
1014-
const root = await makeTempRoot();
1015-
const source = path.join(root, "hermes");
993+
const { root, source } = await makeHermesPaths();
1016994
await writeFile(
1017995
path.join(source, "config.yaml"),
1018996
[
@@ -1045,8 +1023,7 @@ describe("Hermes migration config mapping", () => {
10451023
});
10461024

10471025
it("preserves the Hermes Moonshot China endpoint while aligning provider auth", async () => {
1048-
const root = await makeTempRoot();
1049-
const source = path.join(root, "hermes");
1026+
const { root, source } = await makeHermesPaths();
10501027
await writeFile(
10511028
path.join(source, "config.yaml"),
10521029
"model:\n provider: kimi-coding-cn\n default: kimi-k2.5\n",
@@ -1067,8 +1044,7 @@ describe("Hermes migration config mapping", () => {
10671044
});
10681045

10691046
it("maps the Hermes MiniMax China route to OpenClaw's canonical provider", async () => {
1070-
const root = await makeTempRoot();
1071-
const source = path.join(root, "hermes");
1047+
const { root, source } = await makeHermesPaths();
10721048
await writeFile(
10731049
path.join(source, "config.yaml"),
10741050
"model:\n provider: minimax-cn\n default: MiniMax-M2.7\n",
@@ -1096,8 +1072,7 @@ describe("Hermes migration config mapping", () => {
10961072
});
10971073

10981074
it("maps the native Kimi Coding endpoint to Anthropic Messages", async () => {
1099-
const root = await makeTempRoot();
1100-
const source = path.join(root, "hermes");
1075+
const { root, source } = await makeHermesPaths();
11011076
await writeFile(
11021077
path.join(source, "config.yaml"),
11031078
[
@@ -1137,10 +1112,7 @@ describe("Hermes migration config mapping", () => {
11371112
});
11381113

11391114
it("continues independent items after one late config conflict", async () => {
1140-
const root = await makeTempRoot();
1141-
const source = path.join(root, "hermes");
1142-
const workspaceDir = path.join(root, "workspace");
1143-
const stateDir = path.join(root, "state");
1115+
const { source, workspaceDir, stateDir } = await makeHermesPaths();
11441116
const config: Record<string, unknown> = {};
11451117
await writeFile(
11461118
path.join(source, "config.yaml"),

0 commit comments

Comments
 (0)