Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Observe the actual Vitest shard selection for unit receipts

pulse-triage[bot]65357528f86f
diff --git a/frontend-modern/scripts/ci-unit-receipts.mjs b/frontend-modern/scripts/ci-unit-receipts.mjs
index 2e85915fff..aa29725cb6 100644
--- a/frontend-modern/scripts/ci-unit-receipts.mjs
+++ b/frontend-modern/scripts/ci-unit-receipts.mjs
@@ -23,6 +23,21 @@ export default class CIUnitReceipts {
}
this.root = path.resolve(ctx.config.root);
this.modules = new Map();
+ this.sharded = Boolean(ctx.config.shard);
+ if (this.sharded) {
+ // Vitest 4 calls run-start BEFORE the pool shards its inventory. Observe
+ // the actual sequencer call once; do not copy/re-run its selection rule
+ // or mistake another shard's files for missing results in this one.
+ const Sequencer = ctx.config.sequence.sequencer;
+ const reporter = this;
+ ctx.config.sequence.sequencer = class extends Sequencer {
+ async shard(files) {
+ const selected = await super.shard(files);
+ reporter.onShardSelected(selected);
+ return selected;
+ }
+ };
+ }
this.receipt = {
schema_version: 1,
source_sha: this.sourceSha,
@@ -30,6 +45,7 @@ export default class CIUnitReceipts {
.update(fs.readFileSync(path.join(this.root, 'package-lock.json'))).digest('hex'),
shard: ctx.config.shard ?? { index: 1, count: 1 },
inventory_observed: false,
+ selection_observed: false,
test_run_end_observed: false,
test_run_reason: null,
unhandled_error_count: null,
@@ -55,11 +71,29 @@ export default class CIUnitReceipts {
module_error_count: null,
});
}
- this.modules = modules;
+ this.discovered = modules;
+ this.modules = new Map();
this.receipt.inventory_observed = true;
+ this.receipt.discovered_module_count = modules.size;
+ this.receipt.selection_observed = false;
this.receipt.test_run_end_observed = false;
this.receipt.test_run_reason = null;
this.receipt.unhandled_error_count = null;
+ if (this.sharded) this.write();
+ else this.onShardSelected(specifications);
+ }
+
+ onShardSelected(specifications) {
+ const selected = new Map();
+ for (const spec of specifications) {
+ const entry = this.discovered?.get(spec.taskId);
+ if (!entry || selected.has(spec.taskId)) {
+ throw new Error('Shard selection is absent from the discovered unit inventory');
+ }
+ selected.set(spec.taskId, entry);
+ }
+ this.modules = selected;
+ this.receipt.selection_observed = true;
this.write();
}
@@ -105,7 +139,8 @@ export default class CIUnitReceipts {
const receipt = {
...this.receipt,
// A run-end callback is not an observed process exit or a passing suite.
- collection_complete: this.receipt.inventory_observed && modules.length > 0
+ collection_complete: this.receipt.inventory_observed && this.receipt.selection_observed
+ && modules.length > 0
&& this.receipt.test_run_end_observed
&& this.receipt.test_run_reason !== 'interrupted' && unobserved.length === 0,
unobserved_modules: unobserved,
diff --git a/scripts/tests/frontend-unit-receipts.test.mjs b/scripts/tests/frontend-unit-receipts.test.mjs
index 9d1d7886c2..810d2a4369 100644
--- a/scripts/tests/frontend-unit-receipts.test.mjs
+++ b/scripts/tests/frontend-unit-receipts.test.mjs
@@ -8,14 +8,14 @@ import CIUnitReceipts from '../../frontend-modern/scripts/ci-unit-receipts.mjs';
const sha = 'a'.repeat(40);
-function fixture(t) {
+function fixture(t, config = {}) {
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'unit-receipts-'));
t.after(() => fs.rmSync(root, { recursive: true, force: true }));
const lock = '{"synthetic":"lock"}\n';
fs.writeFileSync(path.join(root, 'package-lock.json'), lock);
const outputFile = path.join(root, 'evidence', 'units.json');
const reporter = new CIUnitReceipts({ outputFile, sourceSha: sha });
- const ctx = { config: { root, shard: { index: 2, count: 4 } } };
+ const ctx = { config: { root, ...config } };
const spec = name => ({
taskId: name, moduleId: path.join(root, `${name}.test.ts`),
project: { name: '' }, pool: 'forks',
@@ -39,8 +39,9 @@ test('initial receipt binds source, lock and actual shard, with no invented inve
const receipt = f.read();
assert.equal(receipt.source_sha, sha);
assert.equal(receipt.package_lock_sha256, createHash('sha256').update(f.lock).digest('hex'));
- assert.deepEqual(receipt.shard, { index: 2, count: 4 });
+ assert.deepEqual(receipt.shard, { index: 1, count: 1 });
assert.equal(receipt.inventory_observed, false);
+ assert.equal(receipt.selection_observed, false);
assert.equal(receipt.collection_complete, false);
assert.equal(receipt.test_run_end_observed, false);
assert.equal(receipt.test_run_reason, null);
@@ -51,6 +52,35 @@ test('initial receipt binds source, lock and actual shard, with no invented inve
assert.equal(fs.statSync(f.outputFile).mode & 0o777, 0o600);
});
+test('observe the actual sequencer selection once, returning its unchanged array and sort behaviour', async t => {
+ let calls = 0;
+ let returned;
+ class Sequencer {
+ async shard(files) { calls++; returned = files.slice(1, 2); return returned; }
+ sort(files) { return files; }
+ }
+ const { reporter, ctx, spec, module, read } = fixture(t, {
+ shard: { index: 2, count: 4 }, sequence: { sequencer: Sequencer },
+ });
+ const discovered = ['outside-a', 'selected', 'outside-b', 'outside-c'].map(spec);
+ reporter.onTestRunStart(discovered);
+ assert.equal(read().inventory_observed, true);
+ assert.equal(read().selection_observed, false);
+ assert.deepEqual(read().modules, []);
+ const sequencer = new ctx.config.sequence.sequencer(ctx);
+ assert.ok(sequencer instanceof Sequencer);
+ assert.equal(await sequencer.shard(discovered), returned);
+ assert.equal(calls, 1, 'never independently predict or re-run sharding');
+ assert.equal(sequencer.sort(discovered), discovered);
+ assert.equal(read().discovered_module_count, 4);
+ assert.deepEqual(read().modules.map(m => m.id), ['selected']);
+ assert.deepEqual(read().unobserved_modules, ['selected']);
+ assert.deepEqual(read().shard, { index: 2, count: 4 });
+ reporter.onTestRunEnd([module('selected')], [], 'passed');
+ assert.equal(read().collection_complete, true);
+ assert.equal(read().modules.length, 1);
+});
+
test('completed failure and success survive while another selected module is unobserved', t => {
const { reporter, spec, module, read, outputFile } = fixture(t);
reporter.onTestRunStart(['z-held', 'b-pass', 'a-fail'].map(spec));