Skip to content
Source
Sign inSign up
TanStack/db
Open History to see the last commit

release-history-oracle.js

350 lines11.4 KB

1/**
2 * Release laws come from CONTRIBUTING.md's Changesets and Releases sections:
3 * candidates start at 1.0.0-rc.1, patches extend the current candidate, and a
4 * minor or major starts the next candidate. Stable packages use ordinary semver
5 * and latest. Candidates also use latest (maintainer decision 2026-10-29,
6 * recorded in CONTRIBUTING.md). Versioning consumes each changeset once.
7 * Exit promotes candidates to 1.0.0 and applies only still-pending work.
8 *
9 * This independent model uses numeric tuples and an authored changeset ledger.
10 * It imports no Changesets planner, production version helper, manifest parser,
11 * or registry classifier. The bounded dependency law uses workspace:* edges:
12 * changing their published exact target requires a dependent patch, as the
13 * repository's updateInternalDependencies=patch policy specifies. Compatible
14 * peers do not require that patch. This is not an arbitrary semver-range model.
15 *
16 * The model predicts manifests, consumed IDs and unique changelog tokens after
17 * each version action, and successful version/tag writes after publishing.
18 * npm HTTP, tarballs, installed consumers, general workspace discovery and
19 * clean installation are separate receiving boundaries, not claims here.
20 */
21import assert from 'node:assert/strict'
22​
23export const packageNames = {
24 db: '@tanstack/db',
25 react: '@tanstack/react-db',
26 query: '@tanstack/query-db-collection',
27 offline: '@tanstack/offline-transactions',
29​
30// Exhaust these semantic boundaries rather than randomizing a larger grammar.
31// Removing boundary loses numeric 9->10; removing dependency loses stable
32// dependent exit; removing strongest loses major-vs-minor precedence. Reversing
33// pending insertion order must not change the maximum requested release type.
34export const releaseHistories = [
35 'first',
36 'candidate-nine',
37 'patch-nine',
38].flatMap((boundary) =>
39 [false, true].flatMap((stableDependency) =>
40 ['minor', 'major'].flatMap((strongest) =>
41 [false, true].flatMap((reverse) =>
42 ['none', 'stable-only', 'candidate-and-stable'].map((exitWork) => ({
43 boundary,
44 stableDependency,
45 strongest,
46 reverse,
47 exitWork,
48 })),
49 ),
50 ),
51 ),
53​
54export const publishHistories = [
55 '1.0.0-rc.1.9',
56 '1.0.0-rc.1.10',
57 '1.0.0-rc.9',
58 '1.0.0-rc.10',
59].flatMap((candidate) =>
60 ['stable-history', 'only-rc', 'never', 'current'].flatMap((registry) =>
61 (registry === 'current' ? ['none'] : ['none', 'stable', 'candidate']).map(
62 (failure) => ({
63 candidate,
64 registry,
65 failure,
66 }),
67 ),
68 ),
70​
71// HTTP reception exhausts the original fourteen metadata/failure forms, then
72// adds independent neighboring facts. Exact version presence and tag shape are
73// separate: a tag is not proof that another version is absent. Heterogeneous
74// assignments also prohibit treating all candidate manifests as one version.
75// Bounded enumeration has direct replay by the complete unique Vitest title;
76// it makes no seeded/random-schedule or arbitrary-semver coverage claim.
77export const httpPublishHistories = [
78 ...publishHistories
79 .filter(({ candidate }) => candidate === '1.0.0-rc.1.10')
80 .flatMap((history) =>
81 ['only-rc', 'current'].includes(history.registry)
82 ? ['rc-only', 'latest-alias'].map((tagShape) => ({
83 ...history,
84 tagShape,
85 }))
86 : [{ ...history, tagShape: 'ordinary' }],
87 ),
88 ...['latest-only', 'no-tags', 'older-rc', 'older-rc-latest-current'].map(
89 (tagShape) => ({
90 candidate: '1.0.0-rc.1.10',
91 registry: 'current',
92 failure: 'none',
93 tagShape,
94 }),
95 ),
96 {
97 candidate: '1.0.0-rc.1.10',
98 registry: 'current',
99 failure: 'none',
100 tagShape: 'latest-alias',
101 stableTagShape: 'no-tags',
102 },
103 ...['none', 'candidate'].map((failure) => ({
104 candidate: '1.0.0-rc.1.10',
105 registry: 'only-rc',
106 failure,
107 tagShape: 'no-tags',
108 })),
109 ...[false, true].flatMap((reverse) =>
110 [
111 { currentCandidate: undefined, failure: 'none' },
112 { currentCandidate: undefined, failure: 'candidate-after-success' },
113 { currentCandidate: 'db', failure: 'none' },
114 { currentCandidate: 'react', failure: 'none' },
115 ].map(({ currentCandidate, failure }) => ({
116 candidate: reverse ? '1.0.0-rc.2' : '1.0.0-rc.1.10',
117 reactCandidate: reverse ? '1.0.0-rc.1.10' : '1.0.0-rc.2',
118 registry: currentCandidate === undefined ? 'stable-history' : 'only-rc',
119 tagShape: currentCandidate === undefined ? 'ordinary' : 'latest-alias',
120 ...(currentCandidate === undefined ? {} : { currentCandidate }),
121 failure,
122 })),
123 ),
125​
126export const seedFailureHistories = [
127 'first-manifest',
128 'second-manifest',
129 'release-config',
130 'before-pre',
131 'after-pre',
132 'changelog',
133 'after-apply',
134].flatMap((failure) =>
135 [false, true].map((stableDependency) => ({ failure, stableDependency })),
137​
138const strength = { none: 0, patch: 1, minor: 2, major: 3 }
139const strongest = (a, b) => (strength[a] >= strength[b] ? a : b)
140const copy = (value) => structuredClone(value)
141​
142export function createReleaseModel(stableDependency) {
143 return {
144 mode: 'before',
145 versions: {
146 db: { candidate: 0, patch: 0 },
147 react: { candidate: 0, patch: 0 },
148 query: [1, 4, 8],
149 offline: [1, 1, 4],
150 },
151 stableDependency,
152 pending: [],
153 consumed: [],
154 tokens: Object.fromEntries(
155 Object.keys(packageNames).map((key) => [key, []]),
156 ),
157 }
159​
160export function queueRelease(model, id, releases) {
161 assert(!model.pending.some((entry) => entry.id === id))
162 assert(!model.consumed.includes(id), 'changeset IDs cannot be reused')
163 for (const [key, type] of Object.entries(releases)) {
164 assert(
165 key in packageNames,
166 'the grammar names only public fixture packages',
167 )
168 assert(type in strength && type !== 'none', 'a release requires a bump')
169 }
170 model.pending.push({ id, releases: { ...releases } })
172​
173// Pending IDs and consumed IDs differ even when public versions match: a later
174// version action must apply one and ignore the other. Candidate patch/counter
175// states also differ: the next patch and minor distinguish their numeric value.
176export function applyReleaseVersion(model, { exit = false } = {}) {
177 const next = copy(model)
178 const requested = Object.fromEntries(
179 Object.keys(packageNames).map((key) => [key, 'none']),
180 )
181 for (const entry of next.pending)
182 for (const [key, type] of Object.entries(entry.releases))
183 requested[key] = strongest(requested[key], type)
184 if (exit) {
185 requested.db = strongest(requested.db, 'patch')
186 requested.react = strongest(requested.react, 'patch')
187 }
188 if (requested.db !== 'none') {
189 requested.react = strongest(requested.react, 'patch')
190 if (next.stableDependency)
191 requested.offline = strongest(requested.offline, 'patch')
192 }
193 for (const key of Object.keys(packageNames)) {
194 const type = requested[key]
195 if (type === 'none') continue
196 const old = next.versions[key]
197 if ('candidate' in old) {
198 next.versions[key] = exit
199 ? [1, 0, 0]
200 : type === 'patch'
201 ? { candidate: old.candidate, patch: old.patch + 1 }
202 : { candidate: old.candidate + 1, patch: 0 }
203 } else {
204 const [major, minor, patch] = old
205 next.versions[key] =
206 type === 'major'
207 ? [major + 1, 0, 0]
208 : type === 'minor'
209 ? [major, minor + 1, 0]
210 : [major, minor, patch + 1]
211 }
212 }
213 for (const entry of next.pending) {
214 next.consumed.push(entry.id)
215 for (const key of Object.keys(entry.releases))
216 next.tokens[key].push({ id: entry.id, version: modelVersions(next)[key] })
217 }
218 next.pending = []
219 next.mode = exit ? 'stable' : 'rc'
220 return next
222​
223export function modelVersions(model) {
224 return Object.fromEntries(
225 Object.entries(model.versions).map(([key, value]) => [
226 key,
227 Array.isArray(value)
228 ? value.join('.')
229 : `1.0.0-rc.${value.candidate}${value.patch ? `.${value.patch}` : ''}`,
230 ]),
231 )
233​
234export function checkReleaseObservation(actual, model, checkpoint) {
235 const expected = modelVersions(model)
236 assert.deepEqual(actual.versions, expected, `${checkpoint}: package versions`)
237 // Order among independent same-version entries is not promised. Preserve
238 // multiplicity, package and version attribution while comparing the bag.
239 const tokens = (ledger) =>
240 Object.fromEntries(
241 Object.entries(ledger).map(([key, entries]) => [
242 key,
243 entries.map(({ id, version }) => `${version}:${id}`).sort(),
244 ]),
245 )
246 assert.deepEqual(
247 tokens(actual.tokens),
248 tokens(model.tokens),
249 `${checkpoint}: changelog ledger`,
250 )
251 assert.deepEqual(
252 actual.privateManifest,
253 actual.originalPrivateManifest,
254 `${checkpoint}: private package is unchanged`,
255 )
256 assert.deepEqual(
257 actual.ignoredDependency,
258 'workspace:*',
259 `${checkpoint}: ignored dev dependency is restored`,
260 )
261 if (model.mode === 'rc') {
262 assert.deepEqual(actual.pre.mode, 'pre', `${checkpoint}: prerelease mode`)
263 assert.deepEqual(
264 [...actual.pre.changesets].sort(),
265 [...model.consumed].sort(),
266 `${checkpoint}: exactly consumed IDs`,
267 )
268 assert.deepEqual(
269 actual.changesets.sort(),
270 [...model.consumed, ...model.pending.map((entry) => entry.id)].sort(),
271 `${checkpoint}: prerelease files remain replayable`,
272 )
273 } else {
274 assert.equal(
275 actual.pre,
276 undefined,
277 `${checkpoint}: exit removes prerelease state`,
278 )
279 assert.deepEqual(
280 actual.changesets,
281 [],
282 `${checkpoint}: exit removes consumed files`,
283 )
284 }
285 assert.equal(
286 actual.dependencies.react,
287 'workspace:*',
288 `${checkpoint}: candidate direct dependency retains pack-time protocol`,
289 )
290 if (model.stableDependency)
291 assert.equal(
292 actual.dependencies.offline,
293 'workspace:*',
294 `${checkpoint}: stable direct dependency retains pack-time protocol`,
295 )
296 else
297 assert.equal(
298 actual.dependencies.offline,
299 '^1.0.0-rc.0',
300 `${checkpoint}: compatible stable peer stays broad`,
301 )
302 assert.equal(
303 actual.dependencies.query,
304 '^1.0.0-rc.0',
305 `${checkpoint}: query peer retains RC capability requirement`,
306 )
308​
309// Registry histories are external input, never a release-tag classifier. A
310// successful publish writes the documented tag even if all old versions were
311// candidates. Concurrent independent package attempts may arrive in any order.
312export function expectedPublishes(manifests, registry) {
313 return manifests
314 .filter(
315 (manifest) =>
316 !manifest.private &&
317 !registry[manifest.name].versions.includes(manifest.version),
318 )
319 .map((manifest) => ({
320 name: manifest.name,
321 version: manifest.version,
322 tag: 'latest',
323 }))
325​
326export function checkPublishObservation(
327 actual,
328 expected,
329 checkpoint,
330 expectedRegistry = 'http://127.0.0.1:4873',
331) {
332 const key = ({ name, version, tag }) => `${name}@${version}:${tag}`
333 const successes = actual.filter(
334 (entry) => entry.type === 'publish' && entry.success,
335 )
336 assert.deepEqual(
337 successes.map(key).sort(),
338 expected.map(key).sort(),
339 `${checkpoint}: each unpublished version reaches its documented tag once`,
340 )
341 for (const entry of actual) {
342 assert.equal(
343 entry.registry,
344 expectedRegistry,
345 `${checkpoint}: local registry only`,
346 )
347 if (entry.type === 'publish')
348 assert.equal(entry.access, 'public', `${checkpoint}: public access`)
349 }