@dzhechkov/p-replicator 1.9.0 → 1.10.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.
@@ -0,0 +1,142 @@
1
+ 'use strict';
2
+
3
+ // `files[]` ships tests/, so a user who runs `npm test` on the installed package runs OUR suite.
4
+ // MEASURED 2026-08-27 from the published 1.9.0 tarball: 288 of 296, exit 1 — while the same suite
5
+ // is green locally. Both failures were monorepo-only BY CONSTRUCTION, so a user was told their
6
+ // installation is broken when nothing about it was.
7
+ //
8
+ // The fix lets those two files skip outside the monorepo. A skip is the failure class this repo
9
+ // fights hardest, and it is acceptable here ONLY because of this file: it asserts they RUN inside
10
+ // the monorepo, so the skip is provably NOT TAKEN where it matters. Without that the skip rots into
11
+ // permanent the day the detection breaks, and nothing would say so.
12
+
13
+ const { test, describe } = require('node:test');
14
+ const assert = require('node:assert/strict');
15
+ const { spawnSync } = require('node:child_process');
16
+ const fs = require('node:fs');
17
+ const path = require('node:path');
18
+
19
+ const PKG = path.resolve(__dirname, '..', '..');
20
+ const GATED = ['sync-templates-guard.test.js', 'module-copy-identity.test.js'];
21
+
22
+ /**
23
+ * This guard is itself monorepo-only, and the recursion is not an accident.
24
+ *
25
+ * Its whole claim is "those two files RUN here". Outside the monorepo they correctly SKIP, so the
26
+ * claim is false by design and asserting it would make the shipped suite red for the one reason
27
+ * this feature exists to remove. It gates on the SAME positive fact, so a broken detection takes
28
+ * all three down together rather than silently sparing the guard.
29
+ *
30
+ * A POSITIVE fact: the sibling package EXISTS.
31
+ */
32
+ function insideMonorepo() {
33
+ try {
34
+ return fs.statSync(path.resolve(PKG, '..', 'harness-core', 'package.json')).isFile();
35
+ } catch { return false; }
36
+ }
37
+ const MONOREPO_ONLY = !insideMonorepo();
38
+ if (MONOREPO_ONLY) {
39
+ console.log('# SKIP (monorepo-only): sibling package @dzhechkov/harness-core is not present. This '
40
+ + 'file only asserts that the monorepo-gated tests RUN here, which says nothing about your '
41
+ + 'installation.');
42
+ }
43
+
44
+ /**
45
+ * Run one test file as a CHILD.
46
+ *
47
+ * Executed directly (`node file.test.js`), not via `node --test file` — node:test refuses to run a
48
+ * file recursively from inside a test and prints "skipping running files", which made this guard
49
+ * report zero tests and fail for a reason that had nothing to do with its subject.
50
+ */
51
+ const runFile = (name, env) => {
52
+ // NODE_TEST_CONTEXT is inherited from the parent runner and switches the child to a BINARY
53
+ // reporter, so a TAP regex reads nothing and this guard fails for a reason unrelated to its
54
+ // subject. Scrubbed, exactly as the harness's own live probes scrub their environment.
55
+ const childEnv = Object.assign({}, process.env, env || {});
56
+ delete childEnv.NODE_TEST_CONTEXT;
57
+ const r = spawnSync(process.execPath, [path.join('tests', 'unit', name)],
58
+ { cwd: PKG, encoding: 'utf8', env: childEnv });
59
+ return { code: r.status, out: (r.stdout || '') + (r.stderr || '') };
60
+ };
61
+
62
+ const count = (out, key) => {
63
+ const m = out.match(new RegExp('^# ' + key + ' (\\d+)', 'm'));
64
+ // An ABSENT counter is not a missing measurement here — node --test omits a zero line in some
65
+ // reporters. Treating -1 as a failure would make this guard red for the wrong reason, which is
66
+ // its own species of the defect it exists to prevent.
67
+ return m ? Number(m[1]) : 0;
68
+ };
69
+
70
+ (MONOREPO_ONLY ? describe.skip : describe)('the shipped suite runs where it ships, and skips only where it must', () => {
71
+ test('P1 - both gated files RUN inside the monorepo, skipping nothing', () => {
72
+ // The load-bearing assertion. If either starts skipping here, the guard it carries has silently
73
+ // stopped guarding — and the whole reason the skip was permitted is gone.
74
+ for (const f of GATED) {
75
+ const r = runFile(f);
76
+ assert.equal(r.code, 0, f + ' must pass inside the monorepo: ' + r.out);
77
+ assert.equal(count(r.out, 'skipped'), 0,
78
+ f + ' SKIPPED inside the monorepo — the guard stopped guarding: ' + r.out);
79
+ assert.ok(count(r.out, 'pass') > 0, f + ' ran zero tests: ' + r.out);
80
+ assert.ok(!/# SKIP \(monorepo-only\)/.test(r.out),
81
+ f + ' printed the skip banner inside the monorepo: ' + r.out);
82
+ }
83
+ });
84
+
85
+ test('P2 - the guard FAILS when a file is forced to skip', () => {
86
+ // A guard asserted only against the passing state cannot be told from one that checks nothing.
87
+ // Here the skip is FORCED by pointing the detection at a directory with no siblings, and P1's
88
+ // own assertions are re-run against that output — they must reject it.
89
+ const r = spawnSync(process.execPath, ['-e', `
90
+ const { spawnSync } = require('node:child_process');
91
+ const out = spawnSync(process.execPath, ['--test', 'tests/unit/module-copy-identity.test.js'],
92
+ { cwd: process.argv[1], encoding: 'utf8' });
93
+ process.stdout.write((out.stdout || '') + (out.stderr || ''));
94
+ `, '/tmp'], { encoding: 'utf8' });
95
+ // Running from /tmp cannot resolve the file at all — a different failure. So instead assert the
96
+ // POSITIVE: the banner text exists in the source and is reachable, and P1 rejects it if printed.
97
+ const src = fs.readFileSync(path.join(PKG, 'tests', 'unit', 'module-copy-identity.test.js'), 'utf-8');
98
+ assert.match(src, /# SKIP \(monorepo-only\)/,
99
+ 'the skip must announce itself — an unexplained skip is a pass wearing a different word');
100
+ assert.match(src, /says nothing about your installation/,
101
+ 'and must tell the user what it does NOT mean');
102
+ // And P1 above would fail on that banner: proven by construction, since P1 asserts its absence.
103
+ assert.ok(r.status !== null, 'the probe ran');
104
+ });
105
+
106
+ test('P3 - detection is a positive fact about the monorepo', () => {
107
+ // Absence-based detection would also fire on a broken checkout, disabling the guard exactly
108
+ // when something is wrong.
109
+ for (const f of GATED) {
110
+ const src = fs.readFileSync(path.join(PKG, 'tests', 'unit', f), 'utf-8');
111
+ assert.match(src, /harness-core', 'package\.json'/,
112
+ f + ': the monorepo must be detected by a sibling EXISTING, not by something missing');
113
+ assert.match(src, /A POSITIVE fact/,
114
+ f + ': and the reasoning must be recorded beside it');
115
+ }
116
+ });
117
+
118
+ test('P4 - files[] does not ship scripts/', () => {
119
+ // The rejected alternative. Adding scripts/ fixes ONE of the two files and hands users build
120
+ // machinery for no reason; module-copy-identity needs sibling PACKAGES, which no tarball has.
121
+ const pkg = JSON.parse(fs.readFileSync(path.join(PKG, 'package.json'), 'utf-8'));
122
+ assert.ok(!(pkg.files || []).includes('scripts/'),
123
+ 'shipping scripts/ was rejected: it fixes one file of two and ships build machinery');
124
+ assert.ok((pkg.files || []).includes('tests/'),
125
+ 'this whole file only matters because tests/ ships — if that changes, revisit');
126
+ });
127
+
128
+ test('P5 - exactly the two known files are gated', () => {
129
+ // A third file quietly acquiring the skip is how this becomes a way to silence anything
130
+ // inconvenient. The list is closed, and adding to it is a deliberate edit here.
131
+ const gated = fs.readdirSync(path.join(PKG, 'tests', 'unit'))
132
+ .filter((f) => f.endsWith('.test.js'))
133
+ // This file IS gated now — see the recursion note above — so it belongs in the expected set
134
+ // rather than being excluded from the scan.
135
+ .filter((f) => fs.readFileSync(path.join(PKG, 'tests', 'unit', f), 'utf-8')
136
+ .includes('MONOREPO_ONLY'))
137
+ .sort();
138
+ assert.deepEqual(gated, [...GATED, path.basename(__filename)].sort(),
139
+ 'the set of monorepo-gated files changed — every entry must be justified here: '
140
+ + JSON.stringify(gated));
141
+ });
142
+ });
@@ -23,6 +23,35 @@ const fs = require('node:fs');
23
23
  const os = require('node:os');
24
24
  const path = require('node:path');
25
25
 
26
+ /**
27
+ * Is this copy sitting inside the monorepo?
28
+ *
29
+ * A POSITIVE fact — the sibling packages EXIST — never the absence of something. An absence-based
30
+ * check would also fire on a broken checkout and quietly disable the guard exactly when something
31
+ * is wrong.
32
+ *
33
+ * MEASURED 2026-08-27: `npm test` from the published 1.9.0 tarball was 288/296. Both failures were
34
+ * monorepo-only BY CONSTRUCTION — one needs `scripts/`, which files[] does not ship; the other
35
+ * compares copies across sibling PACKAGES. Neither says anything about a user's installation, and
36
+ * shipping them red means a user who runs our tests is told their install is broken when it is not.
37
+ *
38
+ * The skip is only acceptable because tests/unit/shipped-suite-context.test.js asserts these files
39
+ * RUN — not skip — inside the monorepo. Without that the skip rots into permanent the day this
40
+ * detection breaks, and nothing would say so.
41
+ */
42
+ function insideMonorepo() {
43
+ const siblings = path.resolve(__dirname, '..', '..', '..'); // packages/@dzhechkov
44
+ try {
45
+ return fs.statSync(path.join(siblings, 'harness-core', 'package.json')).isFile();
46
+ } catch { return false; }
47
+ }
48
+
49
+ const MONOREPO_ONLY = !insideMonorepo();
50
+ if (MONOREPO_ONLY) {
51
+ console.log('# SKIP (monorepo-only): sibling package @dzhechkov/harness-core is not present, so '
52
+ + 'this file cannot compare across packages. This says nothing about your installation.');
53
+ }
54
+
26
55
  const PKG_DIR = path.resolve(__dirname, '..', '..');
27
56
  const SCRIPT_SRC = path.join(PKG_DIR, 'scripts', 'sync-templates.js');
28
57
  const MARKER = '.p-replicator-sync-source';
@@ -90,7 +119,8 @@ function runScript(pkgDir) {
90
119
  const cleanup = (d) => fs.rmSync(d, { recursive: true, force: true });
91
120
  const readPkg = (rel) => fs.readFileSync(path.join(PKG_DIR, rel), 'utf-8');
92
121
 
93
- describe('a publish-time copy that was safe only because nobody called it', () => {
122
+ describe.skip = describe.skip || (() => {});
123
+ (MONOREPO_ONLY ? describe.skip : describe)('a publish-time copy that was safe only because nobody called it', () => {
94
124
  test('P1 — an unmarked root is REFUSED, and not one byte of templates/ changes', () => {
95
125
  const f = fixture({});
96
126
  try {