Skip to content

Commit 927d46f

Browse files
authored
test(i18n): parse the modality catalogs outside the test process (#19229)
The file parsed all 67 catalogs (about 80 MB of JSON) in the test process, so --test-force-exit called process.exit() with the heap at its limit and Sparkplug/Maglev jobs still running. Those jobs park until the main thread collects garbage while process.exit() joins them, which hung whichever unit shard held this file until the job timed out (nodejs/node#64274, fix proposed in nodejs/node#66171). A short-lived child now parses the catalogs and ends on its own, and the test process receives only the keys it asserts on. All assertions stay. Locally, with the CI flags on Node 24.22.2, about 600 runs hung 4 times before this change and 1260 runs hung 0 times after it. Ref #19203
1 parent 120403b commit 927d46f

1 file changed

Lines changed: 46 additions & 22 deletions

File tree

‎tests/unit/modality-bridge-video-i18n.test.ts‎

Lines changed: 46 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import assert from "node:assert/strict";
2-
import { readdirSync, readFileSync } from "node:fs";
2+
import { execFileSync } from "node:child_process";
33
import path from "node:path";
44
import test from "node:test";
55
import i18nConfig from "../../config/i18n.json" with { type: "json" };
@@ -18,28 +18,57 @@ const requiredKeys = [
1818
"modalityBridgeVideoFrameCount",
1919
"modalityBridgeVideoMaxVideos",
2020
] as const;
21+
const inspectedKeys = [
22+
...requiredKeys,
23+
"modalityBridgeIntro",
24+
"modalityBridgeVideoComingSoon",
25+
] as const;
26+
27+
type CatalogSettings = Partial<Record<(typeof inspectedKeys)[number], unknown>>;
28+
29+
// Parse the catalogs in a short-lived child, never in this process. They add up to about 80 MB
30+
// of JSON, and parsing them here left the heap at its limit with concurrent Sparkplug/Maglev jobs
31+
// still running when --test-force-exit called process.exit(). Such a job parks until the main
32+
// thread collects garbage while process.exit() joins it, so this file hung the shard it landed on
33+
// until the job timed out (nodejs/node#64274, fix proposed in nodejs/node#66171, unreleased). The
34+
// child ends on its own: isolate teardown wakes parked jobs, which process.exit() does not do.
35+
const CATALOG_READER = `
36+
const fs = require("node:fs");
37+
const path = require("node:path");
38+
const [directory, keys] = [process.argv[1], JSON.parse(process.argv[2])];
39+
const catalogs = {};
40+
for (const file of fs.readdirSync(directory).filter((entry) => entry.endsWith(".json")).sort()) {
41+
const { settings } = JSON.parse(fs.readFileSync(path.join(directory, file), "utf8"));
42+
catalogs[file] = settings
43+
? Object.fromEntries(keys.filter((key) => Object.hasOwn(settings, key)).map((key) => [key, settings[key]]))
44+
: null;
45+
}
46+
process.stdout.write(JSON.stringify(catalogs));
47+
`;
48+
49+
const settingsByCatalog = JSON.parse(
50+
execFileSync(
51+
process.execPath,
52+
["-e", CATALOG_READER, messagesDirectory, JSON.stringify(inspectedKeys)],
53+
{ encoding: "utf8" }
54+
)
55+
) as Record<string, CatalogSettings | null>;
2156

2257
test(`all ${i18nConfig.locales.length} UI locale catalogs contain non-placeholder Video Bridge settings`, () => {
23-
const catalogs = readdirSync(messagesDirectory)
24-
.filter((file) => file.endsWith(".json"))
25-
.sort();
58+
const catalogs = Object.keys(settingsByCatalog);
2659
assert.equal(catalogs.length, i18nConfig.locales.length);
27-
const english = JSON.parse(readFileSync(path.join(messagesDirectory, "en.json"), "utf8")) as {
28-
settings: Record<string, string>;
29-
};
60+
const english = settingsByCatalog["en.json"]!;
3061
for (const file of catalogs) {
31-
const catalog = JSON.parse(readFileSync(path.join(messagesDirectory, file), "utf8")) as {
32-
settings?: Record<string, unknown>;
33-
};
62+
const settings = settingsByCatalog[file];
3463
for (const key of requiredKeys) {
35-
const value = catalog.settings?.[key];
64+
const value = settings?.[key];
3665
assert.equal(typeof value, "string", `${file}: settings.${key} missing`);
3766
assert.ok(String(value).trim().length > 0, `${file}: settings.${key} empty`);
3867
assert.equal(String(value).startsWith("__MISSING__:"), false, `${file}: ${key} placeholder`);
3968
if (file !== "en.json" && key !== "modalityBridgeVideoTitle") {
4069
assert.notEqual(
4170
value,
42-
english.settings[key],
71+
english[key],
4372
`${file}: settings.${key} copied from English instead of translated`
4473
);
4574
}
@@ -48,24 +77,19 @@ test(`all ${i18nConfig.locales.length} UI locale catalogs contain non-placeholde
4877
});
4978

5079
test("localized Modality Bridge copy describes the shipped Video Bridge without stale backlog text", () => {
51-
const ptBr = JSON.parse(readFileSync(path.join(messagesDirectory, "pt-BR.json"), "utf8")) as {
52-
settings: Record<string, string>;
53-
};
80+
const ptBr = settingsByCatalog["pt-BR.json"]!;
5481
assert.equal(
55-
ptBr.settings.modalityBridgeIntro,
82+
ptBr.modalityBridgeIntro,
5683
"Converta conteúdo multimodal em texto antes que ele chegue a modelos apenas de texto. As pontes de visão, áudio e vídeo estão disponíveis e podem ser configuradas."
5784
);
5885
assert.equal(
59-
ptBr.settings.modalityBridgeVideoDesc,
86+
ptBr.modalityBridgeVideoDesc,
6087
"Faça uma amostragem dos quadros do vídeo, descreva-os com um modelo de visão e continue com o modelo de texto escolhido."
6188
);
6289

63-
for (const file of readdirSync(messagesDirectory).filter((entry) => entry.endsWith(".json"))) {
64-
const catalog = JSON.parse(readFileSync(path.join(messagesDirectory, file), "utf8")) as {
65-
settings: Record<string, unknown>;
66-
};
90+
for (const [file, settings] of Object.entries(settingsByCatalog)) {
6791
assert.equal(
68-
Object.hasOwn(catalog.settings, "modalityBridgeVideoComingSoon"),
92+
Object.hasOwn(settings!, "modalityBridgeVideoComingSoon"),
6993
false,
7094
`${file}: stale Video Bridge backlog key`
7195
);

0 commit comments

Comments
 (0)