@impz/testing 7.8.0 → 7.9.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.
Files changed (2) hide show
  1. package/dist/index.js +95 -29
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -21750,6 +21750,11 @@ function resolveMaxMemoryMib(memoryMib, requested) {
21750
21750
  message: `the max memory (${String(requested)} MiB) is more than ${String(MAX_GROWTH_FACTOR)} \xD7 the memory (${String(ceiling)} MiB): memory the guest grows into cannot hold its kernel's own allocations, so raise the memory too`
21751
21751
  });
21752
21752
  }
21753
+ if (requested > memoryMib && (memoryMib % BLOCK_MIB !== 0 || requested % BLOCK_MIB !== 0)) {
21754
+ throw new ImpdError("BAD_REQUEST", {
21755
+ message: `an imp that grows needs a memory (${String(memoryMib)} MiB) and a max memory (${String(requested)} MiB) of whole ${String(BLOCK_MIB)} MiB blocks`
21756
+ });
21757
+ }
21753
21758
  return requested;
21754
21759
  }
21755
21760
  function toWholeBlocks(mib) {
@@ -21811,6 +21816,7 @@ var EnvSchema = z54.object({
21811
21816
  IMP_KSM_EXEC: z54.string().default("ksm-exec"),
21812
21817
  IMP_KSM_HEADROOM_PERCENT: z54.string().default("100"),
21813
21818
  IMP_HUGE_PAGES: z54.enum(["off", "2M"]).default("off"),
21819
+ IMP_ELASTIC_TRANSPARENT_HUGE_PAGES: z54.enum(["on", "off"]).default("on"),
21814
21820
  IMP_UFFD_HANDLER: z54.string().default("uffd-handler"),
21815
21821
  IMP_WARM_CAP_MIB: CountSchema3.default(2048),
21816
21822
  IMP_DNS: z54.string().default("1.1.1.1,8.8.8.8").transform(splitList).pipe(DnsServersSchema),
@@ -21985,6 +21991,7 @@ function loadConfig(env) {
21985
21991
  jailDir: join4(parsed.IMP_DATA_DIR, "jail"),
21986
21992
  ksm: parseKsmConfig(parsed),
21987
21993
  hugePages: parsed.IMP_HUGE_PAGES === "2M" ? { handlerBin: parsed.IMP_UFFD_HANDLER, warmCapMib: parsed.IMP_WARM_CAP_MIB } : null,
21994
+ isElasticTransparentHugePages: parsed.IMP_ELASTIC_TRANSPARENT_HUGE_PAGES === "on",
21988
21995
  kernelPath: join4(parsed.IMP_DATA_DIR, "system", "vmlinux"),
21989
21996
  kernelSource: parsed.IMP_KERNEL ?? null,
21990
21997
  systemDriveSource: parsed.IMP_SYSTEM_DRIVE ?? join4(parsed.IMP_DATA_DIR, "system", "imp-system.squashfs"),
@@ -22145,13 +22152,13 @@ function readHostAddresses() {
22145
22152
  }
22146
22153
 
22147
22154
  // packages/daemon/src/impd/create-impd.ts
22148
- import { readFileSync as readFileSync38 } from "fs";
22155
+ import { readFileSync as readFileSync39 } from "fs";
22149
22156
  import { release as release2 } from "os";
22150
22157
  import { join as join49 } from "path";
22151
22158
  // packages/daemon/package.json
22152
22159
  var package_default = {
22153
22160
  name: "@impz/daemon",
22154
- version: "7.8.0",
22161
+ version: "7.9.0",
22155
22162
  private: true,
22156
22163
  description: "impd: the imp host daemon",
22157
22164
  type: "module",
@@ -25788,7 +25795,7 @@ var SnapshotIdentitySchema = z62.object({
25788
25795
  ipv6Prefix: z62.string().nullable().optional(),
25789
25796
  cpuModel: z62.string().optional(),
25790
25797
  cpuFlags: z62.string().optional(),
25791
- hugePages: z62.enum(["None", "2M"]).optional()
25798
+ hugePages: z62.enum(["None", "2M", "Transparent"]).optional()
25792
25799
  });
25793
25800
  var AGENT_RECORD_JSON = { useProtoFieldName: true, alwaysEmitImplicit: true };
25794
25801
  var SeenSessionJsonSchema = z62.json().transform((json, ctx) => {
@@ -29473,7 +29480,7 @@ var VmIdentitySchema = z70.object({
29473
29480
  ipv6Prefix: z70.string().nullable().optional(),
29474
29481
  cpuModel: z70.string().optional(),
29475
29482
  cpuFlags: z70.string().optional(),
29476
- hugePages: z70.enum(["None", "2M"]).optional()
29483
+ hugePages: z70.enum(["None", "2M", "Transparent"]).optional()
29477
29484
  });
29478
29485
  function readHostIdentity(firecrackerBin, systemFiles, ipv6Prefix = null) {
29479
29486
  return {
@@ -43128,7 +43135,7 @@ async function createImpdFirewall(config, deps, secretFiles, plan) {
43128
43135
  }
43129
43136
 
43130
43137
  // packages/daemon/src/impd/create-impd-imps.ts
43131
- import { readFileSync as readFileSync35 } from "fs";
43138
+ import { readFileSync as readFileSync36 } from "fs";
43132
43139
  import { availableParallelism } from "os";
43133
43140
 
43134
43141
  // packages/daemon/src/host-net/net/read-guest-net-bytes.ts
@@ -44560,7 +44567,7 @@ function createMarks() {
44560
44567
  return { marks, setMark };
44561
44568
  }
44562
44569
  var BASE_BOOT_ARGS = [
44563
- "console=ttyS0 reboot=k panic=1 pci=off",
44570
+ "console=ttyS0 quiet loglevel=5 reboot=k panic=1 pci=off",
44564
44571
  "i8042.noaux i8042.nomux i8042.nopnp i8042.dumbkbd",
44565
44572
  "root=/dev/vdb rootfstype=squashfs ro init=/imp-agent"
44566
44573
  ];
@@ -44745,7 +44752,7 @@ var TemplateMetaSchema = z86.object({
44745
44752
  buildId: z86.string(),
44746
44753
  vcpus: z86.int().positive(),
44747
44754
  memoryMib: z86.int().positive(),
44748
- hugePages: z86.enum(["None", "2M"]).default("None"),
44755
+ hugePages: z86.enum(["None", "2M", "Transparent"]).default("None"),
44749
44756
  systemDrivePath: z86.string()
44750
44757
  });
44751
44758
 
@@ -46709,6 +46716,7 @@ function createImpContext(deps) {
46709
46716
  readSleepRamMib: deps.config.ksm === null ? deps.readRamMib : deps.readUnsharedRamMib,
46710
46717
  checkGuestMerge: deps.checkGuestMerge,
46711
46718
  probeUffdDevice: deps.probeUffdDevice,
46719
+ probeTransparentHugePages: deps.probeTransparentHugePages,
46712
46720
  mergeFlags: createMergeFlags(),
46713
46721
  memoryLimit: deps.memoryLimit ?? NO_MEMORY_LIMIT,
46714
46722
  priorityNames,
@@ -48148,12 +48156,27 @@ function formatPageHandler(stats) {
48148
48156
  }
48149
48157
 
48150
48158
  // packages/daemon/src/imps/imps/pick-huge-pages.ts
48151
- function pickHugePages(isOn, imp) {
48152
- return isOn && imp.maxMemoryMib <= imp.memoryMib && imp.memoryMib % 2 === 0 ? "2M" : "None";
48159
+ function pickHugePages(settings, imp) {
48160
+ if (imp.memoryMib % 2 !== 0) {
48161
+ return "None";
48162
+ }
48163
+ if (imp.maxMemoryMib > imp.memoryMib) {
48164
+ return settings.isElasticTransparent && imp.maxMemoryMib % 2 === 0 ? "Transparent" : "None";
48165
+ }
48166
+ return settings.isOn ? "2M" : "None";
48167
+ }
48168
+ function readPageSettings(context) {
48169
+ return {
48170
+ isOn: context.config.hugePages !== null,
48171
+ isElasticTransparent: context.config.isElasticTransparentHugePages && context.probeTransparentHugePages()
48172
+ };
48153
48173
  }
48154
48174
 
48155
48175
  // packages/daemon/src/imps/imps/pick-wake-huge-pages.ts
48156
48176
  function pickWakeHugePages(recorded, isOn) {
48177
+ if (recorded === "Transparent") {
48178
+ return "None";
48179
+ }
48157
48180
  if (recorded !== "2M") {
48158
48181
  return null;
48159
48182
  }
@@ -48274,7 +48297,7 @@ function makeWakeImpVm(deps) {
48274
48297
  return imp;
48275
48298
  }
48276
48299
  };
48277
- const canBootOnPool = (imp) => pickHugePages(context.config.hugePages !== null, imp) === "2M";
48300
+ const canBootOnPool = (imp) => pickHugePages({ isOn: context.config.hugePages !== null, isElasticTransparent: false }, imp) === "2M";
48278
48301
  const writeHostPagesIdentity = (imp, paths) => {
48279
48302
  const booted = readVmIdentity(paths);
48280
48303
  if (booted !== null) {
@@ -48740,16 +48763,21 @@ function createFirecrackerClient(socketPath, timeouts = DEFAULT_TIMEOUTS) {
48740
48763
  kernel_image_path: source.kernelImagePath,
48741
48764
  boot_args: source.bootArgs
48742
48765
  }),
48743
- putMachineConfig: (config) => sendPut("/machine-config", {
48744
- vcpu_count: config.vcpuCount,
48745
- mem_size_mib: config.memSizeMib,
48746
- ...config.hugePages === "2M" && { huge_pages: "2M" }
48747
- }),
48766
+ putMachineConfig: async (config) => {
48767
+ if (config.hugePages !== "None" && config.memSizeMib % 2 !== 0) {
48768
+ throw new Error(`${config.hugePages} huge pages need a whole number of 2 MiB pages, and ${String(config.memSizeMib)} MiB is not`);
48769
+ }
48770
+ await sendPut("/machine-config", {
48771
+ vcpu_count: config.vcpuCount,
48772
+ mem_size_mib: config.memSizeMib,
48773
+ ...config.hugePages !== "None" && { huge_pages: config.hugePages }
48774
+ });
48775
+ },
48748
48776
  loadMachineConfig: async () => {
48749
48777
  const parsed = await readAnswer("/machine-config", MachineConfigSchema);
48750
48778
  return {
48751
48779
  isTrackingDirtyPages: parsed.track_dirty_pages === true,
48752
- hugePages: parsed.huge_pages === "2M" ? "2M" : "None"
48780
+ hugePages: readHugePages(parsed.huge_pages)
48753
48781
  };
48754
48782
  },
48755
48783
  putDrive: (drive) => sendPut(`/drives/${drive.driveId}`, {
@@ -48831,6 +48859,9 @@ function createFirecrackerClient(socketPath, timeouts = DEFAULT_TIMEOUTS) {
48831
48859
  }
48832
48860
  };
48833
48861
  }
48862
+ function readHugePages(reported) {
48863
+ return reported === "2M" || reported === "Transparent" ? reported : "None";
48864
+ }
48834
48865
  function toMib(bytes) {
48835
48866
  return Math.floor(bytes / 1048576);
48836
48867
  }
@@ -49110,13 +49141,24 @@ var STALL_FIGURES = [
49110
49141
  ["memory", "memoryStallUs"],
49111
49142
  ["steal", "stealUs"]
49112
49143
  ];
49144
+ var HUGE_PAGE_FIGURES = [
49145
+ ["thp_fault_alloc", "thpFaultAlloc"],
49146
+ ["thp_fault_fallback", "thpFaultFallback"],
49147
+ ["compact_stall", "compactStall"]
49148
+ ];
49113
49149
  function formatHostStall(before, after) {
49114
- const figures = STALL_FIGURES.flatMap(([name, field]) => {
49150
+ const stalls = STALL_FIGURES.flatMap(([name, field]) => {
49115
49151
  const startUs = before[field];
49116
49152
  const endUs = after[field];
49117
49153
  return startUs === null || endUs === null ? [] : [`${name}=${String(Math.round((endUs - startUs) / 1000))}ms`];
49118
49154
  });
49119
- return figures.length === 0 ? "" : `; host stall ${figures.join(" ")}`;
49155
+ const hugePages = HUGE_PAGE_FIGURES.flatMap(([name, field]) => {
49156
+ const start = before[field];
49157
+ const end = after[field];
49158
+ return start === null || end === null ? [] : [`${name}=${String(end - start)}`];
49159
+ });
49160
+ const sections = [...stalls.length === 0 ? [] : [`stall ${stalls.join(" ")}`], ...hugePages];
49161
+ return sections.length === 0 ? "" : `; host ${sections.join(" ")}`;
49120
49162
  }
49121
49163
 
49122
49164
  // packages/daemon/src/imps/imps/start-cold-vm.ts
@@ -49285,7 +49327,7 @@ function createImpVmOps(host) {
49285
49327
  const paths = context.findPaths(imp.id);
49286
49328
  const address = context.findAddress(imp.slot);
49287
49329
  const admitStarted = performance.now();
49288
- const hugePages = pickHugePages(context.config.hugePages !== null, imp);
49330
+ const hugePages = pickHugePages(readPageSettings(context), imp);
49289
49331
  if (hugePages === "2M" && !context.probeUffdDevice()) {
49290
49332
  throw buildUffdDeviceError();
49291
49333
  }
@@ -49324,7 +49366,7 @@ function createImpVmOps(host) {
49324
49366
  ...context.identity,
49325
49367
  agentVersion: vm.agentVersion,
49326
49368
  bootReason: reason,
49327
- ...vm.hugePages === "2M" && { hugePages: vm.hugePages }
49369
+ ...vm.hugePages !== "None" && { hugePages: vm.hugePages }
49328
49370
  });
49329
49371
  await updateImpActivity(context.db, imp.id, new Date);
49330
49372
  await (vm.bootId === undefined ? removeNextBootCause(context.db, imp.id) : writeColdBoot(context.db, imp.id, { bootId: vm.bootId, cause, at: new Date }));
@@ -50032,7 +50074,8 @@ function readHostLoad(sources) {
50032
50074
  cpuStallUs: parsePressureTotal(readProc("pressure", "cpu")),
50033
50075
  ioStallUs: parsePressureTotal(readProc("pressure", "io")),
50034
50076
  memoryStallUs: parsePressureTotal(readProc("pressure", "memory")),
50035
- stealUs: parseStealUs(readProc("stat"))
50077
+ stealUs: parseStealUs(readProc("stat")),
50078
+ ...buildVmstatCounters(readProc("vmstat"))
50036
50079
  };
50037
50080
  }
50038
50081
  function readProcFile(sources, path) {
@@ -50058,6 +50101,17 @@ function parseStealUs(stat) {
50058
50101
  const steal = fields?.[STEAL_FIELD];
50059
50102
  return steal === undefined ? null : Number(steal) * US_PER_TICK;
50060
50103
  }
50104
+ function buildVmstatCounters(vmstat) {
50105
+ const findCounter = (name) => {
50106
+ const found = vmstat === null ? null : new RegExp(`^${name} (?<count>\\d+)$`, "mv").exec(vmstat);
50107
+ return found?.groups?.["count"] === undefined ? null : Number(found.groups["count"]);
50108
+ };
50109
+ return {
50110
+ thpFaultAlloc: findCounter("thp_fault_alloc"),
50111
+ thpFaultFallback: findCounter("thp_fault_fallback"),
50112
+ compactStall: findCounter("compact_stall")
50113
+ };
50114
+ }
50061
50115
 
50062
50116
  // packages/daemon/src/platform/process/read-text.ts
50063
50117
  import { readFileSync as readFileSync33 } from "fs";
@@ -50655,6 +50709,16 @@ function tryWrite(impId, what, write) {
50655
50709
  }
50656
50710
  }
50657
50711
 
50712
+ // packages/daemon/src/vm/vmm/probe-transparent-huge-pages.ts
50713
+ import { readFileSync as readFileSync35 } from "fs";
50714
+ function probeTransparentHugePages(path = "/sys/kernel/mm/transparent_hugepage/enabled") {
50715
+ try {
50716
+ return !readFileSync35(path, "utf8").includes("[never]");
50717
+ } catch {
50718
+ return false;
50719
+ }
50720
+ }
50721
+
50658
50722
  // packages/daemon/src/vm/vmm/probe-uffd-device.ts
50659
50723
  import { accessSync, constants as constants5 } from "fs";
50660
50724
  function probeUffdDevice(path = "/dev/userfaultfd") {
@@ -51081,7 +51145,7 @@ function createImpdImps(config, deps, parts) {
51081
51145
  }), {
51082
51146
  mergeWrapper: config.ksm?.execBin ?? null,
51083
51147
  uffdHandlerBin: config.hugePages?.handlerBin ?? null,
51084
- readFile: readFileSync35
51148
+ readFile: readFileSync36
51085
51149
  });
51086
51150
  const {
51087
51151
  readVmRam,
@@ -51231,6 +51295,7 @@ function resolveImpBoundaries(boundaries) {
51231
51295
  readUnsharedRamMib: boundaries.readUnsharedRamMib ?? readUnsharedRamMib,
51232
51296
  checkGuestMerge: boundaries.checkGuestMerge ?? checkGuestMemoryMergeable,
51233
51297
  probeUffdDevice: boundaries.probeUffdDevice ?? (() => probeUffdDevice()),
51298
+ probeTransparentHugePages: boundaries.probeTransparentHugePages ?? (() => probeTransparentHugePages()),
51234
51299
  readKsmProfitMib: boundaries.readKsmProfitMib ?? readKsmProfitMib,
51235
51300
  readHugePagePool: boundaries.readHugePagePool ?? (() => readHugePagePool()),
51236
51301
  readHugetlbMib: boundaries.readHugetlbMib ?? ((pid, apiSocket) => readHugetlbMibAsync(pid, apiSocket)),
@@ -57301,7 +57366,7 @@ function registerReconcilers(deps) {
57301
57366
  }
57302
57367
 
57303
57368
  // packages/daemon/src/network/https/wire-https-service.ts
57304
- import { readFileSync as readFileSync37 } from "fs";
57369
+ import { readFileSync as readFileSync38 } from "fs";
57305
57370
 
57306
57371
  // packages/daemon/src/platform/db/read-public-imp.ts
57307
57372
  async function readPublicImp(db, name) {
@@ -57325,7 +57390,7 @@ async function listPublicImpNames(db) {
57325
57390
  }
57326
57391
 
57327
57392
  // packages/daemon/src/network/https/acme/cert-store.ts
57328
- import { existsSync as existsSync32, mkdirSync as mkdirSync30, readFileSync as readFileSync36, rmSync as rmSync34 } from "fs";
57393
+ import { existsSync as existsSync32, mkdirSync as mkdirSync30, readFileSync as readFileSync37, rmSync as rmSync34 } from "fs";
57329
57394
  import { join as join48 } from "path";
57330
57395
  import * as z103 from "zod";
57331
57396
  var AttemptStateSchema = z103.object({
@@ -57407,7 +57472,7 @@ ${certificate.chainPem.trimEnd()}
57407
57472
  };
57408
57473
  }
57409
57474
  function readIfExists(path) {
57410
- return existsSync32(path) ? readFileSync36(path, "utf8") : null;
57475
+ return existsSync32(path) ? readFileSync37(path, "utf8") : null;
57411
57476
  }
57412
57477
  function parseJson2(text) {
57413
57478
  try {
@@ -58398,7 +58463,7 @@ function wireHttpsService(options) {
58398
58463
  const issue = createAcmeIssuer({
58399
58464
  directoryUrl: config.acmeDirectory,
58400
58465
  email: config.acmeEmail,
58401
- caPem: config.acmeCaFile === null ? null : readFileSync37(config.acmeCaFile, "utf8"),
58466
+ caPem: config.acmeCaFile === null ? null : readFileSync38(config.acmeCaFile, "utf8"),
58402
58467
  store,
58403
58468
  dns
58404
58469
  });
@@ -60444,7 +60509,7 @@ async function startImpdParts(config, boundaries, plan) {
60444
60509
  readTailnetNames: tailnetNames === null ? null : tailnetNames.readStatus,
60445
60510
  hostReaders: {
60446
60511
  readKernel: () => deps.hostKernelRelease ?? release2(),
60447
- readCpuInfo: deps.readCpuInfo ?? (() => readFileSync38("/proc/cpuinfo", "utf8")),
60512
+ readCpuInfo: deps.readCpuInfo ?? (() => readFileSync39("/proc/cpuinfo", "utf8")),
60448
60513
  readHugePagePool: deps.imps?.readHugePagePool ?? (() => readHugePagePool())
60449
60514
  },
60450
60515
  isReady: () => state.ready,
@@ -61087,7 +61152,7 @@ log tail`);
61087
61152
  }
61088
61153
 
61089
61154
  // packages/testing/src/stand-in/vm/create-stub-uffd-handler.ts
61090
- import { existsSync as existsSync34, readFileSync as readFileSync39, writeFileSync as writeFileSync17 } from "fs";
61155
+ import { existsSync as existsSync34, readFileSync as readFileSync40, writeFileSync as writeFileSync17 } from "fs";
61091
61156
  import { join as join50 } from "path";
61092
61157
  import * as z105 from "zod";
61093
61158
  var StartSchema = z105.object({
@@ -61121,7 +61186,7 @@ exec '${process.execPath}' '${script}' '${mode}' '${recorded}' '${warmAnswer}' "
61121
61186
  };
61122
61187
  }
61123
61188
  function readRecords(path, schema) {
61124
- return existsSync34(path) ? readFileSync39(path, "utf8").trimEnd().split(`
61189
+ return existsSync34(path) ? readFileSync40(path, "utf8").trimEnd().split(`
61125
61190
  `).map((line) => schema.parse(JSON.parse(line))) : [];
61126
61191
  }
61127
61192
 
@@ -61296,6 +61361,7 @@ async function startTestImpd(stack, options = {}) {
61296
61361
  readRssMib: (pid) => fake.alive.has(pid) ? FAKE_VM_RSS_MIB : null,
61297
61362
  readHugePagePool: () => null,
61298
61363
  probeUffdDevice: () => true,
61364
+ probeTransparentHugePages: () => true,
61299
61365
  readHugetlbMib: (pid) => {
61300
61366
  const hugetlbMib = fake.alive.has(pid) ? 0 : null;
61301
61367
  return Promise.resolve(hugetlbMib);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@impz/testing",
3
- "version": "7.8.0",
3
+ "version": "7.9.0",
4
4
  "description": "A real impd on stand-ins, for Bun tests of code that drives impd through @impz/client",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -34,7 +34,7 @@
34
34
  "@zgeoff/kysely-bun-sqlite": "^0.3.3",
35
35
  "@zgeoff/mcp-auth": "^0.3.0",
36
36
  "@zgeoff/std": "^0.4.5",
37
- "@zgeoff/testing": "^0.4.1",
37
+ "@zgeoff/testing": "^0.4.3",
38
38
  "dns-packet": "^5.6.1",
39
39
  "elysia": "^2.0.0-rc.3",
40
40
  "ipaddr.js": "^2.5.0",
@@ -47,7 +47,7 @@
47
47
  "ts-pattern": "^5.9.2",
48
48
  "xstate": "^5.33.3",
49
49
  "zod": "^4.6.7",
50
- "@impz/client": "7.8.0"
50
+ "@impz/client": "7.9.0"
51
51
  },
52
52
  "engines": {
53
53
  "bun": ">=1.4.3"