Open History to see the last commit
1/**
2 * Candidate and stable releases reach latest exactly once.
3 * Authority: CONTRIBUTING.md Changesets/Releases, maintainer decision 2026-10-29.
4 * The existing release ledger supplies the independent version/tag judgment.
5 * This receiver crosses the real npm11/pnpm11/Changesets HTTP boundary, with
6 * the default production publish command and real package-manager archives.
7 * No command shim chooses a tag or fabricates a successful publication.
8 *
9 * The bounded shared grammar retains the original metadata/failure histories
10 * and varies exact-version presence independently of tags. Current candidates
11 * can have only latest, no tags, or rc pointing to an older present version.
12 * A historical old-policy wrong-tag aftermath keeps old rc alongside
13 * latest=current. A separate stable-phase neighbor removes stable latest
14 * while versions remain.
15 * Missing targets also have a no-tags neighbor. Two different candidate
16 * versions vary which package is already current and reverse their assignment.
17 * A later-candidate fault follows an actual successful candidate upload, in
18 * either package order. Retry must retain it without another upload.
19 * Replay selects the complete unique Vitest test title; this finite enumeration
20 * has no seed/shrink interface and claims no arbitrary schedules or semver.
21 *
22 * The fixture supplies local workspace links directly for packing. It disables
23 * automatic installation, isolates configuration/cache/credentials and keeps
24 * HOME unchanged. This establishes HTTP uploads and packed manifest identity,
25 * not repository installation, consumer APIs, production authentication or
26 * GitHub Actions. POSIX process groups are required. Standard tools and their
27 * required loopback socket access are setup premises; missing tools, malformed
28 * protocol or timeout are fixture/runtime failures, not tag-law RED evidence.
29 */
30import assert from 'node:assert/strict'
31import { test } from 'vitest'
32import { declareOracle } from '../packages/db/tests/oracle-declaration.js'
33import { createOracleReach } from '../packages/db/tests/oracle-reach.js'
34import {
35 checkPublishObservation,
36 expectedPublishes,
37 httpPublishHistories,
38 packageNames,
39} from './release-history-oracle.js'
40import { withReleaseWorkspace } from './release-fixture.js'
41import { withHttpPublishReceiver } from './release-http-fixture.js'
42
43const histories = httpPublishHistories
44
45// Final versions and tags follow the authored initial ledger plus each expected
46// successful publication once. This rule does not classify npm's packuments.
47function checkRegistry(state, initial, expected) {
48 const final = structuredClone(initial)
49 for (const { name, version, tag } of expected) {
50 final[name].versions.push(version)
51 final[name].tags[tag] = version
52 }
53 assert.deepEqual(
54 state.packages,
55 final,
56 'HTTP registry retains each version and its promised tag',
57 )
58}
59
60// Failed attempts are public too: npm forbids publishing an existing exact
61// version. Keep every failure, including duplicates that leave the final ledger
62// unchanged. Only the driver's single authored fault is allowed.
63function checkHttpUploadFailures(uploads, controlledFailure) {
64 const failures = uploads
65 .filter(({ success }) => !success)
66 .map(({ name, controlledFailure, duplicate }) => ({
67 name,
68 controlledFailure,
69 duplicate,
70 }))
71 assert.deepEqual(
72 failures,
73 controlledFailure === undefined
74 ? []
75 : [
76 {
77 name: controlledFailure.name,
78 controlledFailure: true,
79 duplicate: false,
80 },
81 ],
82 'HTTP retry does not republish successful or already-current versions',
83 )
84}
85
86function requireSupportedProtocol(state) {
87 const unexpected = state.requests.filter(
88 ({ type }) => type === 'protocol-error' || type === 'request-error',
89 )
90 if (unexpected.length > 0)
91 throw new Error(
92 `HTTP fixture does not support the actual tool protocol: ${JSON.stringify(unexpected)}`,
93 )
94}
95
96declareOracle({
97 check: [checkPublishObservation, checkRegistry, checkHttpUploadFailures],
98 model: [expectedPublishes],
99 grammar: [histories],
100})
101
102test('finite HTTP grammar keeps every history independently selectable', () => {
103 assert.equal(
104 new Set(histories.map((history) => JSON.stringify(history))).size,
105 histories.length,
106 'complete JSON test titles identify exactly one history',
107 )
108})
109
110test.each(histories)(
111 'publishes through real npm/pnpm HTTP %j',
112 async (history) => {
113 const reach = createOracleReach(
114 'release.http-registry',
115 [
116 'stable-registry-read',
117 'candidate-registry-read',
118 'registry-read',
119 'restored',
120 'compared',
121 ...(history.registry === 'current'
122 ? ['already-current']
123 : ['packed-upload']),
124 ...(history.failure === 'none'
125 ? []
126 : ['controlled-failure', 'partial-publication', 'retry']),
127 ...(history.tagShape === 'ordinary'
128 ? []
129 : [`metadata-${history.tagShape}`]),
130 ...(history.stableTagShape === 'no-tags'
131 ? ['stable-metadata-no-tags']
132 : []),
133 ...(history.reactCandidate === undefined
134 ? []
135 : ['different-candidate-versions']),
136 ...(history.currentCandidate === undefined
137 ? []
138 : ['mixed-current-and-missing']),
139 ...(history.failure === 'candidate-after-success'
140 ? ['candidate-success-before-failure']
141 : []),
142 ...(history.registry === 'current' ? [] : ['missing-exact-candidate']),
143 ],
144 { replaying: false },
145 )
146 reach.beginHistory()
147 let tools
148 let observation
149 let didFail = false
150 let primary
151 try {
152 await withReleaseWorkspace(async ({ root }) =>
153 withHttpPublishReceiver(root, history, async (receiver) => {
154 tools = receiver.tools
155 const expected = expectedPublishes(
156 receiver.manifests,
157 receiver.initialRegistry,
158 )
159 const before = receiver.bytes()
160 let firstError
161 let retryError
162 let controlledFailure
163 try {
164 await receiver.run()
165 } catch (error) {
166 firstError = error
167 }
168 let state = receiver.readState()
169 observation = state
170 requireSupportedProtocol(state)
171 assert.deepEqual(
172 receiver.bytes(),
173 before,
174 'first HTTP attempt restores original workspace bytes',
175 )
176 if (history.failure === 'none') {
177 if (
178 firstError &&
179 !state.requests.some(({ type }) => type === 'publish')
180 )
181 throw new Error(
182 'HTTP release failed before any publication request',
183 { cause: firstError },
184 )
185 } else {
186 const failed = state.requests.filter(
187 ({ type, controlledFailure }) =>
188 type === 'publish' && controlledFailure,
189 )
190 if (failed.length === 0 || firstError === undefined)
191 throw new Error(
192 'HTTP controlled failure boundary was not received',
193 { cause: firstError },
194 )
195 assert.equal(failed.length, 1, 'one controlled failed HTTP request')
196 controlledFailure = failed[0]
197 if (history.failure === 'candidate-after-success') {
198 assert(
199 [packageNames.db, packageNames.react].includes(
200 controlledFailure.name,
201 ),
202 'the later controlled failure belongs to a candidate',
203 )
204 const failedIndex = state.requests.indexOf(controlledFailure)
205 assert(
206 state.requests
207 .slice(0, failedIndex)
208 .some(
209 ({ type, success, name }) =>
210 type === 'publish' &&
211 success &&
212 [packageNames.db, packageNames.react].includes(name),
213 ),
214 'an actual candidate success precedes the later candidate failure',
215 )
216 reach.reach('candidate-success-before-failure')
217 } else
218 assert.equal(
219 controlledFailure.name,
220 history.failure === 'stable'
221 ? packageNames.query
222 : packageNames.db,
223 )
224 reach.reach('controlled-failure')
225 assert(
226 state.requests.some(
227 ({ type, success }) => type === 'publish' && success,
228 ),
229 'successful partial publications precede retry',
230 )
231 reach.reach('partial-publication')
232 try {
233 await receiver.run()
234 } catch (error) {
235 retryError = error
236 }
237 state = receiver.readState()
238 observation = state
239 requireSupportedProtocol(state)
240 assert.deepEqual(
241 receiver.bytes(),
242 before,
243 'HTTP retry restores original workspace bytes',
244 )
245 reach.reach('retry')
246 }
247 reach.reach('restored')
248 const metadata = state.requests.filter(({ type }) => type === 'info')
249 const infos = new Set(metadata.map(({ name }) => name))
250 // The first GET carries source facts before that package can be uploaded.
251 // A stable-phase duplicate can stop the command before any candidate read.
252 // Record each actual receiving path before judging raw failed attempts.
253 for (const [name, initial] of Object.entries(
254 receiver.initialRegistry,
255 )) {
256 const info = metadata.find((entry) => entry.name === name)
257 if (info !== undefined)
258 assert.deepEqual(
259 { versions: info.versions, tags: info.tags },
260 initial,
261 'real npm receives exact initial version and tag facts',
262 )
263 }
264 const stableRead = [packageNames.query, packageNames.offline].every(
265 (name) => infos.has(name),
266 )
267 const candidateRead = [packageNames.db, packageNames.react].every(
268 (name) => infos.has(name),
269 )
270 if (stableRead) {
271 reach.reach('stable-registry-read')
272 if (history.stableTagShape === 'no-tags')
273 reach.reach('stable-metadata-no-tags')
274 }
275 if (candidateRead) {
276 reach.reach('candidate-registry-read')
277 if (history.tagShape !== 'ordinary')
278 reach.reach(`metadata-${history.tagShape}`)
279 if (history.reactCandidate !== undefined) {
280 assert.notEqual(
281 receiver.manifests[0].version,
282 receiver.manifests[1].version,
283 )
284 reach.reach('different-candidate-versions')
285 }
286 const candidateExpected = expected.filter(({ name }) =>
287 [packageNames.db, packageNames.react].includes(name),
288 )
289 if (history.currentCandidate !== undefined) {
290 assert.equal(
291 candidateExpected.length,
292 1,
293 'exactly one candidate target is missing',
294 )
295 reach.reach('mixed-current-and-missing')
296 }
297 if (history.registry !== 'current') {
298 assert(
299 candidateExpected.length > 0,
300 'at least one exact candidate target is missing',
301 )
302 reach.reach('missing-exact-candidate')
303 }
304 }
305 if (stableRead && candidateRead) reach.reach('registry-read')
306 const uploads = state.requests.filter(
307 ({ type }) => type === 'publish',
308 )
309 checkHttpUploadFailures(uploads, controlledFailure)
310 assert.deepEqual(
311 [...infos].sort(),
312 Object.values(packageNames).sort(),
313 'both package phases reached registry metadata',
314 )
315 if (history.failure === 'none')
316 assert.equal(
317 firstError,
318 undefined,
319 'publication without controlled failure fulfills',
320 )
321 else
322 assert.equal(
323 retryError,
324 undefined,
325 'retry after controlled failure fulfills',
326 )
327 for (const upload of uploads) {
328 assert.deepEqual(
329 { name: upload.archive.name, version: upload.archive.version },
330 { name: upload.name, version: upload.version },
331 'real packed manifest matches publication',
332 )
333 assert(upload.archive.files > 0, 'actual packed files arrived')
334 }
335 if (history.registry === 'current') {
336 assert.equal(
337 uploads.length,
338 0,
339 'already-current registry requires no uploads',
340 )
341 reach.reach('already-current')
342 } else {
343 assert(uploads.length > 0, 'real packed publication path ran')
344 reach.reach('packed-upload')
345 }
346 checkPublishObservation(
347 state.requests,
348 expected,
349 'real HTTP publication and optional retry',
350 receiver.origin,
351 )
352 checkRegistry(state, receiver.initialRegistry, expected)
353 reach.reach('compared')
354 reach.assertReached()
355 }),
356 )
357 } catch (error) {
358 didFail = true
359 primary = error
360 throw error
361 } finally {
362 if (process.env.TANSTACK_DB_ORACLE_STATISTICS === '1') {
363 try {
364 console.info(
365 'HTTP release reach',
366 JSON.stringify({
367 history,
368 tools,
369 states: Object.fromEntries(reach.counts()),
370 observation,
371 }),
372 )
373 } catch (report) {
374 throw didFail
375 ? new AggregateError(
376 [primary, report],
377 'HTTP release comparison and reach reporting failures',
378 { cause: primary },
379 )
380 : report
381 }
382 }
383 }
384 },
385 45_000,
386)
387
388test.each(['already-current', 'retained-success'])(
389 'rejects duplicate HTTP attempts for %s',
390 (shape) => {
391 const fault = {
392 name: packageNames.query,
393 success: false,
394 controlledFailure: true,
395 duplicate: false,
396 }
397 const duplicate = {
398 name: packageNames.db,
399 success: false,
400 controlledFailure: false,
401 duplicate: true,
402 }
403 const actual =
404 shape === 'already-current' ? [duplicate] : [fault, duplicate]
405 assert.throws(
406 () =>
407 checkHttpUploadFailures(
408 actual,
409 shape === 'already-current' ? undefined : fault,
410 ),
411 /HTTP retry does not republish/,
412 )
413 },
414)
415
416test.each(['default', 'variable-origin', 'foreign-origin'])(
417 'retains registry-origin judgment %s',
418 (shape) => {
419 const expected = [
420 { name: packageNames.db, version: '1.0.0-rc.1.10', tag: 'rc' },
421 ]
422 const registry =
423 shape === 'default' ? 'http://127.0.0.1:4873' : 'http://127.0.0.1:61234'
424 const observation = [
425 {
426 ...expected[0],
427 type: 'publish',
428 success: true,
429 access: 'public',
430 registry,
431 },
432 ]
433 if (shape === 'default')
434 checkPublishObservation(observation, expected, 'default origin')
435 else {
436 checkPublishObservation(
437 observation,
438 expected,
439 'variable loopback origin',
440 registry,
441 )
442 if (shape === 'foreign-origin')
443 assert.throws(() =>
444 checkPublishObservation(
445 [{ ...observation[0], registry: 'https://example.invalid' }],
446 expected,
447 'foreign observation',
448 registry,
449 ),
450 )
451 }
452 },
453)