@wildshard/shard-format 0.69.2 → 0.71.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.
- package/package.json +21 -3
- package/src/cli/corpus-candidate.ts +228 -0
- package/src/cli/corpus-command.ts +67 -0
- package/src/cli/corpus-pins.ts +73 -0
- package/src/cli/corpus-report.ts +36 -0
- package/src/cli/corpus-tar.ts +28 -0
- package/src/cli/corpus-usage.ts +106 -0
- package/src/cli/corpus.ts +50 -68
- package/src/cli/format-diff-data.ts +89 -0
- package/src/cli/format-diff-lock.ts +122 -0
- package/src/cli/format-diff-normal.ts +300 -0
- package/src/cli/format-diff-paths.ts +103 -0
- package/src/cli/format-diff-range.ts +112 -0
- package/src/cli/format-diff-report.ts +30 -0
- package/src/cli/format-diff-rules.ts +232 -0
- package/src/cli/format-diff.ts +226 -0
- package/src/cli/main.ts +81 -32
- package/src/cli/pack.ts +20 -3
- package/src/cli/validate.ts +1 -1
- package/src/format/clientOwnership.ts +1 -1
- package/src/format/clientTrails.ts +121 -46
- package/src/format/cook-data.ts +22 -3
- package/src/format/cook-deprecations.ts +53 -0
- package/src/format/cook-preparation.ts +105 -70
- package/src/format/creature-rest-rig.ts +248 -0
- package/src/format/creature-skin-bounds.ts +146 -0
- package/src/format/deprecations.ts +30 -21
- package/src/format/edge-observations.ts +67 -0
- package/src/format/empty-shardfile.ts +4 -2
- package/src/format/entry-read-set.ts +147 -0
- package/src/format/format-migrate-rebuild.ts +4 -1
- package/src/format/format-migrate.ts +10 -5
- package/src/format/format-migration-envelope.ts +40 -0
- package/src/format/format-migration-prune.ts +42 -1
- package/src/format/format-migrations.ts +10 -1
- package/src/format/format-window.ts +71 -0
- package/src/format/immutable.ts +4 -1
- package/src/format/json-schema.ts +1468 -0
- package/src/format/lootEconomy.ts +4 -1
- package/src/format/mat4.ts +225 -0
- package/src/format/memory-armed.json +1 -9
- package/src/format/memory-armed.ts +46 -17
- package/src/format/memory-epoch.ts +10 -3
- package/src/format/memory-line.ts +17 -6
- package/src/format/outputFields.ts +3 -2
- package/src/format/outputIndex.ts +41 -6
- package/src/format/platformDataSections.ts +5 -0
- package/src/format/platformFileFamilies.ts +3 -3
- package/src/format/play-area.ts +95 -0
- package/src/format/policy-verdict.ts +12 -2
- package/src/format/preparation-checks.ts +100 -0
- package/src/format/preparation-spec.ts +45 -0
- package/src/format/registeredJson.ts +2 -2
- package/src/format/runtime-tier.ts +14 -7
- package/src/format/save-revision.ts +105 -0
- package/src/format/schema-source.ts +70 -0
- package/src/format/sections.ts +4 -1
- package/src/format/server-plan.ts +42 -0
- package/src/format/server-reads.ts +23 -0
- package/src/format/shardSchema.ts +9 -4
- package/src/format/shardSections.ts +17 -7
- package/src/format/shardfile-assets.ts +5 -5
- package/src/format/shardfile-stream-admit.ts +19 -10
- package/src/format/shardfile-stream-facts.ts +2 -1
- package/src/format/shardfile-stream.ts +2 -3
- package/src/format/shardfileValidation.ts +16 -9
- package/src/format/species-deprecations.ts +79 -0
- package/src/format/stateLineage.ts +15 -7
- package/src/format/tread-boxes.ts +65 -0
- package/src/format/vehicle-hulls.ts +124 -0
- package/src/format/version.ts +96 -10
- package/src/format/whole-inputs.ts +51 -0
- package/src/tools/runtime-hosts.json +4 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wildshard/shard-format",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.71.0",
|
|
4
4
|
"description": "The raw shardfile format: the spec, the validator and a validate CLI. The public, versioned contract every other repo builds on.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"repository": {
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
"src/format/*.ts",
|
|
20
20
|
"!src/format/*.test.ts",
|
|
21
21
|
"!src/format/*.golden-specs.ts",
|
|
22
|
+
"!src/format/lock/**",
|
|
22
23
|
"src/format/memoryGates.json",
|
|
23
24
|
"src/format/memory-armed.json",
|
|
24
25
|
"src/format/empty-shardfile.json",
|
|
@@ -57,6 +58,7 @@
|
|
|
57
58
|
"./audioMeasure": "./src/format/audio-measure.ts",
|
|
58
59
|
"./audioRules": "./src/format/audio-rules.ts",
|
|
59
60
|
"./audioWaiver": "./src/format/audio-waiver.ts",
|
|
61
|
+
"./jsonSchema": "./src/format/json-schema.ts",
|
|
60
62
|
"./shardfileAudio": "./src/format/shardfile-audio.ts",
|
|
61
63
|
"./audioRouting": "./src/format/audioRouting.ts",
|
|
62
64
|
"./audioScene": "./src/format/audioScene.ts",
|
|
@@ -130,6 +132,7 @@
|
|
|
130
132
|
"./discoveryValues": "./src/format/discoveryValues.ts",
|
|
131
133
|
"./easedFields": "./src/format/easedFields.ts",
|
|
132
134
|
"./edgeProfiles": "./src/format/edgeProfiles.ts",
|
|
135
|
+
"./edgeObservations": "./src/format/edge-observations.ts",
|
|
133
136
|
"./eliteContinuation": "./src/format/eliteContinuation.ts",
|
|
134
137
|
"./eliteEntryRows": "./src/format/eliteEntryRows.ts",
|
|
135
138
|
"./eliteFeature": "./src/format/eliteFeature.ts",
|
|
@@ -160,6 +163,14 @@
|
|
|
160
163
|
"./forestPage": "./src/format/forestPage.ts",
|
|
161
164
|
"./forestWeather": "./src/format/forestWeather.ts",
|
|
162
165
|
"./geometryPack": "./src/format/geometryPack.ts",
|
|
166
|
+
"./creatureRestRig": "./src/format/creature-rest-rig.ts",
|
|
167
|
+
"./creatureSkinBounds": "./src/format/creature-skin-bounds.ts",
|
|
168
|
+
"./playArea": "./src/format/play-area.ts",
|
|
169
|
+
"./entryReadSet": "./src/format/entry-read-set.ts",
|
|
170
|
+
"./serverReads": "./src/format/server-reads.ts",
|
|
171
|
+
"./wholeInputs": "./src/format/whole-inputs.ts",
|
|
172
|
+
"./treadBoxes": "./src/format/tread-boxes.ts",
|
|
173
|
+
"./vehicleHulls": "./src/format/vehicle-hulls.ts",
|
|
163
174
|
"./glbBuffers": "./src/format/glbBuffers.ts",
|
|
164
175
|
"./glbCost": "./src/format/glbCost.ts",
|
|
165
176
|
"./glbImages": "./src/format/glbImages.ts",
|
|
@@ -240,6 +251,7 @@
|
|
|
240
251
|
"./outputDownload": "./src/format/outputDownload.ts",
|
|
241
252
|
"./outputFields": "./src/format/outputFields.ts",
|
|
242
253
|
"./outputIndex": "./src/format/outputIndex.ts",
|
|
254
|
+
"./preparationSpec": "./src/format/preparation-spec.ts",
|
|
243
255
|
"./overdraw": "./src/format/overdraw.ts",
|
|
244
256
|
"./pageLife": "./src/format/pageLife.ts",
|
|
245
257
|
"./pagePreparation": "./src/format/pagePreparation.ts",
|
|
@@ -458,6 +470,10 @@
|
|
|
458
470
|
"test:ci": "node --test 'src/ci/**/*.test.ts'",
|
|
459
471
|
"test:chain": "node --test 'src/tools/*.chain.ts'",
|
|
460
472
|
"test:format": "vitest run src/format --testTimeout=30000 --maxWorkers=2",
|
|
473
|
+
"lock:write": "node src/tools/format-lock.ts --write",
|
|
474
|
+
"check:lock": "node src/tools/format-lock.ts",
|
|
475
|
+
"check:format-gate": "node src/tools/format-gate.ts",
|
|
476
|
+
"corpus:usage": "node src/cli/main.ts corpus --cache tmp/corpus --usage corpus/usage.json --pins https://raw.githubusercontent.com/project-wildshard/engine/main/test/pins/shardfiles.json",
|
|
461
477
|
"check:asks": "node kit/scripts/asks.mjs check",
|
|
462
478
|
"check:agents": "node .githooks/agents-md.mjs lint",
|
|
463
479
|
"check:parity": "node scripts/agent-parity.mjs --strict",
|
|
@@ -466,13 +482,15 @@
|
|
|
466
482
|
"agents:sync": "node scripts/agent-sync.mjs",
|
|
467
483
|
"md:wrap": "node kit/scripts/md-wrap.mjs",
|
|
468
484
|
"test:hooks": "node --test '.githooks/*.test.mjs'",
|
|
469
|
-
"check": "pnpm check:bin-pins && pnpm typecheck && pnpm lint && pnpm lint:format && pnpm format:check && pnpm test && pnpm test:format && pnpm check:asks && pnpm check:agents && pnpm check:agent-sync && pnpm test:agent-hooks && pnpm check:parity && node --check scripts/chromium-keychain-check.mjs && node --test test/tooling/chrome-keychain.test.mjs test/tooling/disk-land.test.mjs test/tooling/lane-live.test.mjs test/tooling/keep-copy.test.mjs test/tooling/leftovers-report.test.mjs test/tooling/reap-report.test.mjs && pnpm check:wire",
|
|
485
|
+
"check": "pnpm check:bin-pins && pnpm typecheck && pnpm lint && pnpm lint:format && pnpm format:check && pnpm test && pnpm check:lock && pnpm check:format-gate && node --test src/ci/exports-unique.test.ts && pnpm test:format && pnpm check:asks && pnpm check:agents && pnpm check:agent-sync && pnpm test:agent-hooks && pnpm check:parity && node --check scripts/chromium-keychain-check.mjs && node --test test/tooling/chrome-keychain.test.mjs test/tooling/disk-land.test.mjs test/tooling/lane-live.test.mjs test/tooling/keep-copy.test.mjs test/tooling/leftovers-report.test.mjs test/tooling/reap-report.test.mjs && pnpm check:wire",
|
|
470
486
|
"check:wire": "pnpm --dir packages/wire check && pnpm --dir packages/wire test && pnpm check:wire-proofs",
|
|
471
487
|
"check:wire-proofs": "node --test src/scripts/wire/recordings-proof.mjs src/scripts/wire/graph-proof.mjs src/scripts/wire/prepared-frame-proof.mjs",
|
|
472
488
|
"bench": "pnpm --dir packages/wire bench",
|
|
473
|
-
"check:bin-pins": "node kit/scripts/bin-pins.mjs"
|
|
489
|
+
"check:bin-pins": "node kit/scripts/bin-pins.mjs",
|
|
490
|
+
"reupload": "node src/tools/reupload.ts"
|
|
474
491
|
},
|
|
475
492
|
"dependencies": {
|
|
493
|
+
"@valibot/to-json-schema": "1.8.0",
|
|
476
494
|
"meshoptimizer": "1.2.0",
|
|
477
495
|
"valibot": "1.5.0"
|
|
478
496
|
},
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
/** SHARD-COMPAT FE3b (J486 Q51): the corpus runs a candidate chain and validator beside the current one, so a format change
|
|
2
|
+
* is judged against every kept original before it ships. A candidate is a module that names its extra migrations (run
|
|
3
|
+
* after the current chain, over the copy's JSON sections: a candidate's shape is one the current reader refuses) and a
|
|
4
|
+
* check over the copy (the parts the candidate's validator changes). An original is `migrates` when the candidate's
|
|
5
|
+
* steps changed its copy and the copy passes, `valid` when they changed nothing and it passes, and `fails` naming the
|
|
6
|
+
* path the candidate refuses. */
|
|
7
|
+
import { createHash } from 'node:crypto'
|
|
8
|
+
import { readFile } from 'node:fs/promises'
|
|
9
|
+
import path from 'node:path'
|
|
10
|
+
import { pathToFileURL } from 'node:url'
|
|
11
|
+
import { promisify } from 'node:util'
|
|
12
|
+
import { brotliDecompress } from 'node:zlib'
|
|
13
|
+
|
|
14
|
+
import {
|
|
15
|
+
INDEX,
|
|
16
|
+
readJson,
|
|
17
|
+
readSections,
|
|
18
|
+
record,
|
|
19
|
+
rows,
|
|
20
|
+
} from '../format/format-migrate-inventory.ts'
|
|
21
|
+
import { migrateShardfile } from '../format/format-migrate.ts'
|
|
22
|
+
import { FORMAT_MIGRATIONS } from '../format/format-migrations.ts'
|
|
23
|
+
import { readTar } from '../format/tar.ts'
|
|
24
|
+
|
|
25
|
+
import type { JsonRecord } from '../format/format-migrate-inventory.ts'
|
|
26
|
+
import type {
|
|
27
|
+
FormatMigration,
|
|
28
|
+
MigratingShard,
|
|
29
|
+
} from '../format/format-migrations.ts'
|
|
30
|
+
|
|
31
|
+
type Files = ReadonlyMap<string, Uint8Array>
|
|
32
|
+
|
|
33
|
+
/** One part a candidate refuses: the member path and the place in it. */
|
|
34
|
+
interface CandidateFailure {
|
|
35
|
+
readonly path: string
|
|
36
|
+
readonly reason: string
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** A candidate format change, as a module's `candidate` export. */
|
|
40
|
+
interface Candidate {
|
|
41
|
+
readonly id: string
|
|
42
|
+
/** Steps the candidate adds after the current chain, over its JSON sections. */
|
|
43
|
+
readonly migrations?: readonly FormatMigration[]
|
|
44
|
+
/** What the candidate's validator refuses in the migrated copy. */
|
|
45
|
+
readonly check: (files: Files) => readonly CandidateFailure[]
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
interface CandidateVerdict {
|
|
49
|
+
readonly verdict: 'valid' | 'migrates' | 'fails'
|
|
50
|
+
/** The candidate's own steps that changed the copy. */
|
|
51
|
+
readonly applied: readonly string[]
|
|
52
|
+
readonly failures: readonly CandidateFailure[]
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
interface Named {
|
|
56
|
+
readonly shard: string
|
|
57
|
+
readonly revision: number
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const NONE = 0
|
|
61
|
+
const unbrotli = promisify(brotliDecompress)
|
|
62
|
+
const encoder = new TextEncoder()
|
|
63
|
+
|
|
64
|
+
function sha256(bytes: Readonly<Uint8Array>): string {
|
|
65
|
+
return createHash('sha256').update(bytes).digest('hex')
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function isCandidate(value: unknown): value is Candidate {
|
|
69
|
+
return (
|
|
70
|
+
typeof value === 'object' &&
|
|
71
|
+
value !== null &&
|
|
72
|
+
typeof Reflect.get(value, 'id') === 'string' &&
|
|
73
|
+
typeof Reflect.get(value, 'check') === 'function'
|
|
74
|
+
)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** The `candidate` a module exports. */
|
|
78
|
+
async function loadCandidate(module: string): Promise<Candidate> {
|
|
79
|
+
const loaded: unknown = await import(pathToFileURL(path.resolve(module)).href)
|
|
80
|
+
const found: unknown =
|
|
81
|
+
typeof loaded === 'object' && loaded !== null
|
|
82
|
+
? Reflect.get(loaded, 'candidate')
|
|
83
|
+
: undefined
|
|
84
|
+
if (!isCandidate(found)) {
|
|
85
|
+
throw new Error(`${module}: no candidate (id, check) exported`)
|
|
86
|
+
}
|
|
87
|
+
return found
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** The copy's JSON sections as a migrating shard, with each section's member path. */
|
|
91
|
+
function sectionsOf(
|
|
92
|
+
files: Files,
|
|
93
|
+
): Readonly<{ shard: MigratingShard; paths: ReadonlyMap<string, string> }> {
|
|
94
|
+
const index = record(readJson(files, INDEX), INDEX)
|
|
95
|
+
const shard = {
|
|
96
|
+
index,
|
|
97
|
+
sections: readSections(files, index),
|
|
98
|
+
mounts: new Map<string, unknown>(),
|
|
99
|
+
}
|
|
100
|
+
const paths = new Map(
|
|
101
|
+
rows(index['sections']).map(
|
|
102
|
+
(row: Readonly<JsonRecord>): [string, string] => [
|
|
103
|
+
String(row['name']),
|
|
104
|
+
String(row['path']),
|
|
105
|
+
],
|
|
106
|
+
),
|
|
107
|
+
)
|
|
108
|
+
return { shard, paths }
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** Run the candidate's steps over the copy's sections: the ids that changed something, and the rewritten files. */
|
|
112
|
+
function candidateCopy(
|
|
113
|
+
files: Files,
|
|
114
|
+
steps: readonly FormatMigration[],
|
|
115
|
+
): Readonly<{ applied: readonly string[]; files: Files }> {
|
|
116
|
+
const { shard, paths } = sectionsOf(files)
|
|
117
|
+
const applied = steps.filter((step: Readonly<FormatMigration>): boolean => {
|
|
118
|
+
const before = JSON.stringify([...shard.sections])
|
|
119
|
+
step.apply(shard)
|
|
120
|
+
return JSON.stringify([...shard.sections]) !== before
|
|
121
|
+
})
|
|
122
|
+
const out = new Map(files)
|
|
123
|
+
for (const [name, value] of shard.sections) {
|
|
124
|
+
out.set(
|
|
125
|
+
paths.get(name) ?? `sections/${name}.json`,
|
|
126
|
+
encoder.encode(JSON.stringify(value)),
|
|
127
|
+
)
|
|
128
|
+
}
|
|
129
|
+
return {
|
|
130
|
+
applied: applied.map((step: Readonly<FormatMigration>): string => step.id),
|
|
131
|
+
files: out,
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** The current chain's copy, or the reason it cannot run. */
|
|
136
|
+
function currentCopy(files: Files): Files | string {
|
|
137
|
+
try {
|
|
138
|
+
return migrateShardfile(files, {
|
|
139
|
+
hash: sha256,
|
|
140
|
+
migrations: FORMAT_MIGRATIONS,
|
|
141
|
+
}).files
|
|
142
|
+
} catch (error: unknown) {
|
|
143
|
+
return error instanceof Error ? error.message : String(error)
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** Judge one original's files under `candidate`. A chain that cannot run fails with its own reason. */
|
|
148
|
+
function judgeCandidate(
|
|
149
|
+
files: Files,
|
|
150
|
+
candidate: Readonly<Candidate>,
|
|
151
|
+
): CandidateVerdict {
|
|
152
|
+
const copy = currentCopy(files)
|
|
153
|
+
if (typeof copy === 'string') {
|
|
154
|
+
const failures = [{ path: 'chain', reason: copy }]
|
|
155
|
+
return { verdict: 'fails', applied: [], failures }
|
|
156
|
+
}
|
|
157
|
+
const moved = candidateCopy(copy, candidate.migrations ?? [])
|
|
158
|
+
const failures = candidate.check(moved.files)
|
|
159
|
+
if (failures.length > NONE) {
|
|
160
|
+
return { verdict: 'fails', applied: moved.applied, failures }
|
|
161
|
+
}
|
|
162
|
+
const verdict = moved.applied.length > NONE ? 'migrates' : 'valid'
|
|
163
|
+
return { verdict, applied: moved.applied, failures }
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** Judge one stored original (brotli unless `plain`) under `candidate`. */
|
|
167
|
+
async function candidateVerdict(
|
|
168
|
+
file: string,
|
|
169
|
+
plain: boolean,
|
|
170
|
+
candidate: Readonly<Candidate>,
|
|
171
|
+
): Promise<CandidateVerdict> {
|
|
172
|
+
const stored = new Uint8Array(await readFile(file))
|
|
173
|
+
const tar = plain ? stored : new Uint8Array(await unbrotli(stored))
|
|
174
|
+
return judgeCandidate(readTar(tar), candidate)
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** The report's text for one verdict: `migrates (steps)` or `fails path reason; …`. */
|
|
178
|
+
function candidateText(found: Readonly<CandidateVerdict>): string {
|
|
179
|
+
if (found.verdict === 'fails') {
|
|
180
|
+
const parts = found.failures.map(
|
|
181
|
+
(row: Readonly<CandidateFailure>): string => `${row.path} ${row.reason}`,
|
|
182
|
+
)
|
|
183
|
+
return `fails ${parts.join('; ')}`
|
|
184
|
+
}
|
|
185
|
+
return found.verdict === 'migrates'
|
|
186
|
+
? `migrates (${found.applied.join(', ')})`
|
|
187
|
+
: 'valid'
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** The row field a candidate run adds, or none without a candidate. */
|
|
191
|
+
async function candidateField(
|
|
192
|
+
candidate: Readonly<Candidate> | undefined,
|
|
193
|
+
file: string,
|
|
194
|
+
plain: boolean,
|
|
195
|
+
): Promise<Readonly<{ candidate?: string }>> {
|
|
196
|
+
if (candidate === undefined) {
|
|
197
|
+
return {}
|
|
198
|
+
}
|
|
199
|
+
const found = await candidateVerdict(file, plain, candidate)
|
|
200
|
+
return { candidate: candidateText(found) }
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/** Whether a kept original is one `--only` names (`slug`, or `slug@r5`). */
|
|
204
|
+
function onlyNamed(
|
|
205
|
+
only: readonly string[] | undefined,
|
|
206
|
+
revisions: readonly Named[],
|
|
207
|
+
): boolean {
|
|
208
|
+
return (
|
|
209
|
+
only === undefined ||
|
|
210
|
+
revisions.some(
|
|
211
|
+
(named: Named): boolean =>
|
|
212
|
+
only.includes(named.shard) ||
|
|
213
|
+
only.includes(`${named.shard}@r${String(named.revision)}`),
|
|
214
|
+
)
|
|
215
|
+
)
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
export {
|
|
219
|
+
type Candidate,
|
|
220
|
+
type CandidateFailure,
|
|
221
|
+
type CandidateVerdict,
|
|
222
|
+
candidateField,
|
|
223
|
+
candidateText,
|
|
224
|
+
candidateVerdict,
|
|
225
|
+
judgeCandidate,
|
|
226
|
+
loadCandidate,
|
|
227
|
+
onlyNamed,
|
|
228
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises'
|
|
2
|
+
|
|
3
|
+
import { loadCandidate } from './corpus-candidate.ts'
|
|
4
|
+
import { corpusGate, readKnownFailures } from './corpus-gate.ts'
|
|
5
|
+
import { readPins } from './corpus-pins.ts'
|
|
6
|
+
import { corpusReport } from './corpus-report.ts'
|
|
7
|
+
import { corpusUsage, writeUsage } from './corpus-usage.ts'
|
|
8
|
+
import { runCorpus } from './corpus.ts'
|
|
9
|
+
import { readVersion } from './version.ts'
|
|
10
|
+
|
|
11
|
+
import type { CorpusRow } from './corpus.ts'
|
|
12
|
+
|
|
13
|
+
interface CorpusArgs {
|
|
14
|
+
readonly api: string
|
|
15
|
+
readonly cache: string
|
|
16
|
+
readonly usage: string | undefined
|
|
17
|
+
readonly pins: string | undefined
|
|
18
|
+
readonly candidate: string | undefined
|
|
19
|
+
readonly only: string | undefined
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const EXIT_OK = 0
|
|
23
|
+
const EXIT_INVALID = 3
|
|
24
|
+
const NONE = 0
|
|
25
|
+
const KNOWN_FAILURES = 'corpus/known-failures.json'
|
|
26
|
+
|
|
27
|
+
/** Every kept original's row, with engine's pins when `--pins` names them (FE13). */
|
|
28
|
+
async function corpusRows(
|
|
29
|
+
args: Readonly<CorpusArgs>,
|
|
30
|
+
): Promise<Readonly<{ rows: CorpusRow[]; validator: string }>> {
|
|
31
|
+
const validator = await readVersion()
|
|
32
|
+
const pins = args.pins === undefined ? [] : await readPins(args.pins)
|
|
33
|
+
const candidate =
|
|
34
|
+
args.candidate === undefined
|
|
35
|
+
? {}
|
|
36
|
+
: { candidate: await loadCandidate(args.candidate) }
|
|
37
|
+
const only = args.only === undefined ? {} : { only: args.only.split(',') }
|
|
38
|
+
const rows = await runCorpus({
|
|
39
|
+
api: args.api,
|
|
40
|
+
cache: args.cache,
|
|
41
|
+
validator,
|
|
42
|
+
pins,
|
|
43
|
+
...candidate,
|
|
44
|
+
...only,
|
|
45
|
+
})
|
|
46
|
+
return { rows, validator }
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** `shard-format corpus`: every kept original, as stored (FE3), gated by FE5's known failures; `--usage` writes FE13's record. */
|
|
50
|
+
async function corpusCommand(args: Readonly<CorpusArgs>): Promise<number> {
|
|
51
|
+
const { rows, validator } = await corpusRows(args)
|
|
52
|
+
process.stdout.write(`${corpusReport(rows)}\n`)
|
|
53
|
+
if (args.usage !== undefined) {
|
|
54
|
+
await writeUsage(args.usage, corpusUsage(rows, validator, new Date()))
|
|
55
|
+
}
|
|
56
|
+
// SHARD-COMPAT FE5: only a failure not listed with its owner blocks a release.
|
|
57
|
+
const listed = await readFile(KNOWN_FAILURES, 'utf8').catch(
|
|
58
|
+
(): string => '[]',
|
|
59
|
+
)
|
|
60
|
+
const gate = corpusGate(rows, readKnownFailures(listed))
|
|
61
|
+
if (gate.lines.length > NONE) {
|
|
62
|
+
process.stdout.write(`${gate.lines.join('\n')}\n`)
|
|
63
|
+
}
|
|
64
|
+
return gate.blocking.length > NONE ? EXIT_INVALID : EXIT_OK
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export { corpusCommand }
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises'
|
|
2
|
+
|
|
3
|
+
import { array, number, object, parse, pipe, regex, string } from 'valibot'
|
|
4
|
+
|
|
5
|
+
import type { StoredRecord } from './corpus.ts'
|
|
6
|
+
|
|
7
|
+
// SHARD-COMPAT FE13, the pins half: the delete gate counts users over every
|
|
8
|
+
// original GC keeps and every shard file engine pins. `corpus --pins <file or
|
|
9
|
+
// URL>` reads engine's `test/pins/shardfiles.json`; a pinned original the
|
|
10
|
+
// API's public list leaves out (an older revision past GC's window) joins
|
|
11
|
+
// the run, judged by hash like any other.
|
|
12
|
+
|
|
13
|
+
const HASH = pipe(string(), regex(/^[a-f0-9]{64}$/u))
|
|
14
|
+
const PinSchema = object({
|
|
15
|
+
slug: string(),
|
|
16
|
+
revision: number(),
|
|
17
|
+
hash: HASH,
|
|
18
|
+
bytes: number(),
|
|
19
|
+
})
|
|
20
|
+
const PinsSchema = object({ shards: array(PinSchema) })
|
|
21
|
+
|
|
22
|
+
/** One shard file engine pins. */
|
|
23
|
+
interface Pin {
|
|
24
|
+
readonly slug: string
|
|
25
|
+
readonly revision: number
|
|
26
|
+
readonly hash: string
|
|
27
|
+
readonly bytes: number
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const FETCH_TIMEOUT_MS = 60_000
|
|
31
|
+
|
|
32
|
+
async function pinsText(source: string, get: typeof fetch): Promise<string> {
|
|
33
|
+
if (!/^https?:\/\//u.test(source)) {
|
|
34
|
+
return await readFile(source, 'utf8')
|
|
35
|
+
}
|
|
36
|
+
const answer = await get(source, {
|
|
37
|
+
signal: AbortSignal.timeout(FETCH_TIMEOUT_MS),
|
|
38
|
+
})
|
|
39
|
+
if (!answer.ok) {
|
|
40
|
+
throw new Error(`pins ${source}: HTTP ${String(answer.status)}`)
|
|
41
|
+
}
|
|
42
|
+
return await answer.text()
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Engine's shard-file pins, from a file or a URL. */
|
|
46
|
+
async function readPins(
|
|
47
|
+
source: string,
|
|
48
|
+
get: typeof fetch = fetch,
|
|
49
|
+
): Promise<readonly Pin[]> {
|
|
50
|
+
const text = await pinsText(source, get)
|
|
51
|
+
const parsed = parse(PinsSchema, JSON.parse(text))
|
|
52
|
+
return parsed.shards
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** The listed originals, then each pinned one the list leaves out. */
|
|
56
|
+
function withPins(
|
|
57
|
+
listed: readonly StoredRecord[],
|
|
58
|
+
pins: readonly Pin[],
|
|
59
|
+
): readonly StoredRecord[] {
|
|
60
|
+
const known = new Set(
|
|
61
|
+
listed.map((stored: StoredRecord): string => stored.hash),
|
|
62
|
+
)
|
|
63
|
+
const extra = pins
|
|
64
|
+
.filter((pin: Readonly<Pin>): boolean => !known.has(pin.hash))
|
|
65
|
+
.map((pin: Readonly<Pin>): StoredRecord => ({
|
|
66
|
+
hash: pin.hash,
|
|
67
|
+
storedBytes: pin.bytes,
|
|
68
|
+
revisions: [{ shard: pin.slug, revision: pin.revision }],
|
|
69
|
+
}))
|
|
70
|
+
return [...listed, ...extra]
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export { type Pin, readPins, withPins }
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { deprecationLines } from './corpus-deprecations.ts'
|
|
2
|
+
|
|
3
|
+
import type { CorpusRow } from './corpus.ts'
|
|
4
|
+
|
|
5
|
+
// `shard-format corpus`'s text report (FE3): one line per original, the
|
|
6
|
+
// totals, then FE7's deprecation users.
|
|
7
|
+
|
|
8
|
+
const NONE = 0
|
|
9
|
+
const FIRST = 0
|
|
10
|
+
const SHORT_HASH = 12
|
|
11
|
+
const VERDICT_WIDTH = 5
|
|
12
|
+
|
|
13
|
+
function corpusReport(rows: readonly CorpusRow[]): string {
|
|
14
|
+
const lines = rows.map(
|
|
15
|
+
(found: Readonly<CorpusRow>): string =>
|
|
16
|
+
`${found.verdict.padEnd(VERDICT_WIDTH)} ${found.slug} r${String(found.revision)} ${found.hash.slice(FIRST, SHORT_HASH)}${found.reason === undefined ? '' : ` ${found.reason}`}${found.candidate === undefined ? '' : ` | candidate: ${found.candidate}`}`,
|
|
17
|
+
)
|
|
18
|
+
const failed = rows.filter(
|
|
19
|
+
(found: Readonly<CorpusRow>): boolean => found.verdict === 'fails',
|
|
20
|
+
).length
|
|
21
|
+
const fetched = rows.filter(
|
|
22
|
+
(found: Readonly<CorpusRow>): boolean => !found.cached,
|
|
23
|
+
)
|
|
24
|
+
const bytes = fetched.reduce(
|
|
25
|
+
(sum: number, found: Readonly<CorpusRow>): number =>
|
|
26
|
+
sum + found.storedBytes,
|
|
27
|
+
NONE,
|
|
28
|
+
)
|
|
29
|
+
lines.push(
|
|
30
|
+
`corpus: ${String(rows.length)} kept originals, ${String(rows.length - failed)} valid, ${String(failed)} fail; fetched ${String(fetched.length)} (${String(bytes)} stored bytes), ${String(rows.length - fetched.length)} from cache`,
|
|
31
|
+
...deprecationLines(rows),
|
|
32
|
+
)
|
|
33
|
+
return lines.join('\n')
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export { corpusReport }
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/** A downloaded original's first bytes: plain tarball or Brotli (FE3). */
|
|
2
|
+
import { open } from 'node:fs/promises'
|
|
3
|
+
|
|
4
|
+
const NONE = 0
|
|
5
|
+
const TAR_MAGIC_AT = 257
|
|
6
|
+
const TAR_MAGIC = 'ustar'
|
|
7
|
+
const PEEK_BYTES = 512
|
|
8
|
+
|
|
9
|
+
/** Whether the first bytes are a plain tarball (`ustar` at 257) rather than Brotli. */
|
|
10
|
+
function isPlainTar(head: Readonly<Uint8Array>): boolean {
|
|
11
|
+
const magic = new TextDecoder().decode(
|
|
12
|
+
head.subarray(TAR_MAGIC_AT, TAR_MAGIC_AT + TAR_MAGIC.length),
|
|
13
|
+
)
|
|
14
|
+
return magic === TAR_MAGIC
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async function firstBytes(file: string): Promise<Uint8Array> {
|
|
18
|
+
const handle = await open(file)
|
|
19
|
+
try {
|
|
20
|
+
const bytes = new Uint8Array(PEEK_BYTES)
|
|
21
|
+
await handle.read(bytes, NONE, PEEK_BYTES, NONE)
|
|
22
|
+
return bytes
|
|
23
|
+
} finally {
|
|
24
|
+
await handle.close()
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export { firstBytes, isPlainTar }
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { writeFile } from 'node:fs/promises'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
array,
|
|
5
|
+
number,
|
|
6
|
+
optional,
|
|
7
|
+
parse,
|
|
8
|
+
record,
|
|
9
|
+
strictObject,
|
|
10
|
+
string,
|
|
11
|
+
} from 'valibot'
|
|
12
|
+
|
|
13
|
+
import type { CorpusRow } from './corpus.ts'
|
|
14
|
+
|
|
15
|
+
// SHARD-COMPAT FE13: what the delete gate reads. `shard-format corpus
|
|
16
|
+
// --usage <file>` records, for every kept original, the deprecated paths it
|
|
17
|
+
// uses (FE7) and the chain steps it needs to validate (an original the
|
|
18
|
+
// format refuses as stored, judged through the chain: `migrated: <ids>`).
|
|
19
|
+
// A deprecated part or a migration step may be deleted only while its list
|
|
20
|
+
// here is empty and the record is fresh.
|
|
21
|
+
|
|
22
|
+
interface Usage {
|
|
23
|
+
readonly measuredAt: string
|
|
24
|
+
readonly validator: string
|
|
25
|
+
readonly originals: number
|
|
26
|
+
readonly deprecations: Readonly<Record<string, readonly string[]>>
|
|
27
|
+
readonly migrations: Readonly<Record<string, readonly string[]>>
|
|
28
|
+
/** FE13: how many engine-pinned shard files the run covered; absent when it ran without `--pins`. */
|
|
29
|
+
readonly pins?: number | undefined
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const Users = record(string(), array(string()))
|
|
33
|
+
const UsageSchema = strictObject({
|
|
34
|
+
measuredAt: string(),
|
|
35
|
+
validator: string(),
|
|
36
|
+
originals: number(),
|
|
37
|
+
deprecations: Users,
|
|
38
|
+
migrations: Users,
|
|
39
|
+
pins: optional(number()),
|
|
40
|
+
})
|
|
41
|
+
const MIGRATED = 'migrated: '
|
|
42
|
+
const INDENT = 1
|
|
43
|
+
const NO_PINS = 0
|
|
44
|
+
|
|
45
|
+
function add(
|
|
46
|
+
users: Map<string, string[]>,
|
|
47
|
+
ids: readonly string[],
|
|
48
|
+
name: string,
|
|
49
|
+
): void {
|
|
50
|
+
for (const id of ids) {
|
|
51
|
+
users.set(id, [...(users.get(id) ?? []), name])
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function stepsOf(reason: string | undefined): readonly string[] {
|
|
56
|
+
return reason?.startsWith(MIGRATED) === true
|
|
57
|
+
? reason
|
|
58
|
+
.slice(MIGRATED.length)
|
|
59
|
+
.split(',')
|
|
60
|
+
.map((step: string): string => step.trim())
|
|
61
|
+
.filter((step: string): boolean => step !== '')
|
|
62
|
+
: []
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** FE13: how many rows engine pins. */
|
|
66
|
+
function pinsOf(rows: readonly Readonly<CorpusRow>[]): number {
|
|
67
|
+
return rows.filter(
|
|
68
|
+
(found: Readonly<CorpusRow>): boolean => found.pinned === true,
|
|
69
|
+
).length
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Who uses each deprecated path and each chain step, over the kept originals. */
|
|
73
|
+
function corpusUsage(
|
|
74
|
+
rows: readonly Readonly<CorpusRow>[],
|
|
75
|
+
validator: string,
|
|
76
|
+
measuredAt: Readonly<Date>,
|
|
77
|
+
): Usage {
|
|
78
|
+
const deprecations = new Map<string, string[]>()
|
|
79
|
+
const migrations = new Map<string, string[]>()
|
|
80
|
+
for (const found of rows) {
|
|
81
|
+
const name = `${found.slug} r${String(found.revision)}${found.pinned === true ? ' (engine pin)' : ''}`
|
|
82
|
+
add(deprecations, found.deprecations, name)
|
|
83
|
+
add(migrations, stepsOf(found.reason), name)
|
|
84
|
+
}
|
|
85
|
+
const usage: Usage = {
|
|
86
|
+
measuredAt: measuredAt.toISOString(),
|
|
87
|
+
validator,
|
|
88
|
+
originals: rows.length,
|
|
89
|
+
deprecations: Object.fromEntries(deprecations),
|
|
90
|
+
migrations: Object.fromEntries(migrations),
|
|
91
|
+
}
|
|
92
|
+
const pins = pinsOf(rows)
|
|
93
|
+
return pins === NO_PINS ? usage : { ...usage, pins }
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async function writeUsage(file: string, usage: Readonly<Usage>): Promise<void> {
|
|
97
|
+
await writeFile(file, `${JSON.stringify(usage, undefined, INDENT)}\n`)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** A usage record's text, checked. */
|
|
101
|
+
function readUsage(text: string): Usage {
|
|
102
|
+
return parse(UsageSchema, JSON.parse(text))
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export { corpusUsage, readUsage, writeUsage }
|
|
106
|
+
export type { Usage }
|