@wildshard/shard-format 0.69.2 → 0.70.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 +8 -2
- package/src/cli/corpus-command.ts +38 -0
- package/src/cli/corpus-usage.ts +85 -0
- 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-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 +50 -31
- package/src/format/cook-data.ts +22 -3
- package/src/format/cook-preparation.ts +103 -69
- package/src/format/deprecations.ts +12 -0
- package/src/format/format-migrate.ts +3 -4
- package/src/format/format-migration-envelope.ts +21 -0
- package/src/format/format-migrations.ts +2 -0
- package/src/format/outputIndex.ts +28 -6
- package/src/format/preparation-checks.ts +100 -0
- package/src/format/preparation-spec.ts +45 -0
- package/src/format/stateLineage.ts +3 -1
- package/src/format/version.ts +32 -3
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/** The checks `requireCookPreparation` runs on a prepared file (SHARD-COMPAT PR4 and PR5, J487): the preparation
|
|
2
|
+
* marker against `cook.json`'s spec, the fence and the programs mount. */
|
|
3
|
+
import { isPreparationSpec, preparationSpecOf } from './preparation-spec.ts'
|
|
4
|
+
import { validationSourceBytes } from './validationReceipt.ts'
|
|
5
|
+
|
|
6
|
+
import type { AnyPrograms } from './cook-preparation.ts'
|
|
7
|
+
import type { OutputIndex } from './outputIndex.ts'
|
|
8
|
+
|
|
9
|
+
type Frozen<Value> = Value extends object
|
|
10
|
+
? { readonly [Key in keyof Value]: Frozen<Value[Key]> }
|
|
11
|
+
: Value
|
|
12
|
+
|
|
13
|
+
/** Shared by admission and the cook. Legacy sdk 0.2 is an explicit migration boundary. */
|
|
14
|
+
function fenceValid(
|
|
15
|
+
index: Frozen<OutputIndex>,
|
|
16
|
+
lists: Readonly<{
|
|
17
|
+
fence: readonly string[]
|
|
18
|
+
mounts: readonly Readonly<{ hash: string }>[]
|
|
19
|
+
}>,
|
|
20
|
+
fix: string,
|
|
21
|
+
): void {
|
|
22
|
+
const known = new Set<string>()
|
|
23
|
+
for (const file of index.files) {
|
|
24
|
+
known.add(file.hash)
|
|
25
|
+
}
|
|
26
|
+
for (const mount of lists.mounts) {
|
|
27
|
+
known.add(mount.hash)
|
|
28
|
+
}
|
|
29
|
+
for (const row of lists.fence) {
|
|
30
|
+
if (!known.has(row) && !index.requires.commons.includes(row)) {
|
|
31
|
+
throw new Error(`stale fence preparation: run ${fix}`)
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function programMountValid(
|
|
36
|
+
index: Frozen<OutputIndex>,
|
|
37
|
+
cook: {
|
|
38
|
+
readonly programs?: AnyPrograms
|
|
39
|
+
readonly mounts: readonly Readonly<{ url: string; hash: string }>[]
|
|
40
|
+
},
|
|
41
|
+
digest: (bytes: Readonly<Uint8Array>) => string,
|
|
42
|
+
): void {
|
|
43
|
+
const url = `/programs/${index.identity.slug}.json`
|
|
44
|
+
const mount = cook.mounts.find(
|
|
45
|
+
(row: Readonly<{ url: string; hash: string }>): boolean => row.url === url,
|
|
46
|
+
)
|
|
47
|
+
if (
|
|
48
|
+
cook.programs === undefined ||
|
|
49
|
+
mount?.hash !== digest(validationSourceBytes(cook.programs))
|
|
50
|
+
) {
|
|
51
|
+
throw new Error(
|
|
52
|
+
`stale GLSL program mount: run wildshard prepare <folder> --base <exact-preview-url> (${index.identity.slug})`,
|
|
53
|
+
)
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function failureOf(run: () => void): string | undefined {
|
|
57
|
+
try {
|
|
58
|
+
run()
|
|
59
|
+
return undefined
|
|
60
|
+
} catch (error: unknown) {
|
|
61
|
+
return error instanceof Error ? error.message : String(error)
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
const MISMATCH = 'mismatch'
|
|
65
|
+
/** Why the marker and `cook.json` disagree, or `undefined` when they agree. */
|
|
66
|
+
function markerRefusal(
|
|
67
|
+
spec: number | undefined,
|
|
68
|
+
prepared: boolean,
|
|
69
|
+
noMarker: boolean,
|
|
70
|
+
): string | undefined {
|
|
71
|
+
if (spec === undefined) {
|
|
72
|
+
return prepared && noMarker
|
|
73
|
+
? 'cook.json is prepared but shard.json names no preparation spec'
|
|
74
|
+
: undefined
|
|
75
|
+
}
|
|
76
|
+
return prepared ? MISMATCH : 'Missing cook preparation'
|
|
77
|
+
}
|
|
78
|
+
/** PR4: whether the file is prepared, holding `shard.json`'s spec and `cook.json`'s version to each other. */
|
|
79
|
+
function preparationMarked(
|
|
80
|
+
index: Readonly<{ sdk?: unknown; preparation?: unknown }>,
|
|
81
|
+
version: number | undefined,
|
|
82
|
+
fix: string,
|
|
83
|
+
): boolean {
|
|
84
|
+
const spec = preparationSpecOf(index)
|
|
85
|
+
const prepared = isPreparationSpec(version)
|
|
86
|
+
const refusal =
|
|
87
|
+
spec !== undefined && version === spec
|
|
88
|
+
? undefined
|
|
89
|
+
: markerRefusal(spec, prepared, index.sdk === undefined)
|
|
90
|
+
if (refusal !== undefined) {
|
|
91
|
+
throw new Error(
|
|
92
|
+
refusal === MISMATCH
|
|
93
|
+
? `shard.json names preparation spec ${String(spec)}, cook.json is spec ${String(version)}: run ${fix}`
|
|
94
|
+
: `${refusal}: run ${fix}`,
|
|
95
|
+
)
|
|
96
|
+
}
|
|
97
|
+
return spec !== undefined || prepared
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export { failureOf, fenceValid, preparationMarked, programMountValid }
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/** The preparation spec version (SHARD-COMPAT PR4, J487): one number owned by this package, beside the format
|
|
2
|
+
* version. A prepared file records it in `shard.json` `preparation` (format 0.1.0.3 on) and as `cook.json`'s
|
|
3
|
+
* `version`; it names no engine release. Spec 3 still carries the engine renderer fingerprint and program build;
|
|
4
|
+
* spec 4 drops both. See `docs/preparation.md`. */
|
|
5
|
+
|
|
6
|
+
/** `cook.json` version 3: the legacy spec, bound to the engine renderer that recorded it. */
|
|
7
|
+
const LEGACY_PREPARATION_SPEC = 3
|
|
8
|
+
/** The spec a freshly prepared file is made to: no renderer fingerprint, programs with no engine build. */
|
|
9
|
+
const PREPARATION_SPEC = 4
|
|
10
|
+
/** Every preparation spec version a reader of this package accepts. */
|
|
11
|
+
const PREPARATION_SPECS: readonly [
|
|
12
|
+
typeof LEGACY_PREPARATION_SPEC,
|
|
13
|
+
typeof PREPARATION_SPEC,
|
|
14
|
+
] = [LEGACY_PREPARATION_SPEC, PREPARATION_SPEC] as const
|
|
15
|
+
type PreparationSpec = (typeof PREPARATION_SPECS)[number]
|
|
16
|
+
/** The legacy `sdk` marker's prepared value, which always meant spec 3. */
|
|
17
|
+
const PREPARED_SDK = '0.3'
|
|
18
|
+
|
|
19
|
+
/** Whether `version` is a preparation spec this package reads (a prepared `cook.json`). */
|
|
20
|
+
function isPreparationSpec(version: unknown): version is PreparationSpec {
|
|
21
|
+
return PREPARATION_SPECS.some(
|
|
22
|
+
(spec: PreparationSpec): boolean => spec === version,
|
|
23
|
+
)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** The preparation spec a `shard.json` records: `preparation` from format 0.1.0.3, the legacy `sdk: '0.3'` marker as
|
|
27
|
+
* spec 3 before it, `undefined` for an unprepared file. */
|
|
28
|
+
function preparationSpecOf(
|
|
29
|
+
index: Readonly<{ sdk?: unknown; preparation?: unknown }>,
|
|
30
|
+
): PreparationSpec | undefined {
|
|
31
|
+
if (isPreparationSpec(index.preparation)) {
|
|
32
|
+
return index.preparation
|
|
33
|
+
}
|
|
34
|
+
return index.sdk === PREPARED_SDK ? LEGACY_PREPARATION_SPEC : undefined
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export {
|
|
38
|
+
LEGACY_PREPARATION_SPEC,
|
|
39
|
+
PREPARATION_SPEC,
|
|
40
|
+
PREPARATION_SPECS,
|
|
41
|
+
PREPARED_SDK,
|
|
42
|
+
type PreparationSpec,
|
|
43
|
+
isPreparationSpec,
|
|
44
|
+
preparationSpecOf,
|
|
45
|
+
}
|
|
@@ -18,7 +18,9 @@ const measured = { path, hash: v.pipe(v.string(), v.regex(/^[a-f0-9]{64}$/u)),
|
|
|
18
18
|
bytes: v.pipe(v.number(), v.integer(), v.minValue(0), v.maxValue(Number.MAX_SAFE_INTEGER)) };
|
|
19
19
|
const lineageSchemas = v.exactOptional(v.pipe(v.array(v.strictObject(measured)), v.maxLength(128)));
|
|
20
20
|
// SHARD-COMPAT CP14: either envelope; 0.1.0.2 names its format in formatVersion and drops version and schemas.
|
|
21
|
-
const inventory = v.object({ format: v.literal('wildshard.shardfile'), formatVersion: IndexFormatVersionSchema,
|
|
21
|
+
const inventory = v.object({ format: v.literal('wildshard.shardfile'), formatVersion: IndexFormatVersionSchema,
|
|
22
|
+
// SHARD-COMPAT PR4: 0.1.0.3 drops `sdk` for `preparation`; the lineage reader needs neither.
|
|
23
|
+
sdk: v.exactOptional(v.picklist(['0.2', '0.3'])), preparation: v.exactOptional(v.unknown()),
|
|
22
24
|
version: LegacyIndexVersionSchema, identity,
|
|
23
25
|
sections: v.pipe(v.array(v.strictObject({ ...measured, name: v.pipe(v.string(), v.regex(/^[a-z][a-zA-Z0-9-]*\/[a-zA-Z][a-zA-Z0-9_-]*$/u)),
|
|
24
26
|
schema: v.pipe(v.string(), v.maxLength(240)) })), v.maxLength(256)),
|
package/src/format/version.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { LEGACY_PREPARATION_SPEC, PREPARED_SDK } from './preparation-spec.ts'
|
|
2
|
+
|
|
1
3
|
/** Canonical format revision, separate from the npm package and script ABI (J319).
|
|
2
4
|
* The fourth component adds fields; the third changes their meaning. */
|
|
3
5
|
const ZERO = 0
|
|
4
6
|
const ONE = 1
|
|
5
7
|
|
|
6
|
-
const SHARDFILE_VERSION = '0.1.0.
|
|
8
|
+
const SHARDFILE_VERSION = '0.1.0.3'
|
|
7
9
|
/** Formats whose `shard.json` names its version in `version`, beside the frozen layout marker `formatVersion: 2`.
|
|
8
10
|
* Legacy 0.1 is the byte-preserving spelling of 0.1.0.0. */
|
|
9
11
|
const LEGACY_INDEX_VERSIONS: readonly ['0.1', '0.1.0.0', '0.1.0.1'] = [
|
|
@@ -13,7 +15,8 @@ const LEGACY_INDEX_VERSIONS: readonly ['0.1', '0.1.0.0', '0.1.0.1'] = [
|
|
|
13
15
|
] as const
|
|
14
16
|
/** Formats whose `shard.json` names its version in `formatVersion` (SHARD-COMPAT CP14, FORMAT-PRUNE FP25): the
|
|
15
17
|
* layout marker and `version` are gone, so a reader tells the two envelopes apart by the field's type. */
|
|
16
|
-
const INDEX_FORMAT_VERSIONS: readonly [typeof SHARDFILE_VERSION] = [
|
|
18
|
+
const INDEX_FORMAT_VERSIONS: readonly ['0.1.0.2', typeof SHARDFILE_VERSION] = [
|
|
19
|
+
'0.1.0.2',
|
|
17
20
|
SHARDFILE_VERSION,
|
|
18
21
|
] as const
|
|
19
22
|
const SHARDFILE_VERSIONS: readonly [
|
|
@@ -27,6 +30,9 @@ type IndexFormatVersion = (typeof INDEX_FORMAT_VERSIONS)[number]
|
|
|
27
30
|
const LEGACY_LAYOUT = 2
|
|
28
31
|
/** The first format that writes its version in `formatVersion`. */
|
|
29
32
|
const SHARDFILE_VERSION_INDEX_RENAME = '0.1.0.2'
|
|
33
|
+
/** The first format whose `shard.json` records the preparation spec version in `preparation` instead of the `sdk`
|
|
34
|
+
* marker (SHARD-COMPAT PR4, J487; FORMAT-PRUNE FP5 folded in). */
|
|
35
|
+
const SHARDFILE_VERSION_PREPARATION = '0.1.0.3'
|
|
30
36
|
type ShardfileVersionParts = readonly [number, number, number, number]
|
|
31
37
|
|
|
32
38
|
/** Read canonical bounded decimal components; the legacy two-part spelling has zero counters. */
|
|
@@ -111,6 +117,13 @@ function writesIndexFormatVersion(version: string): boolean {
|
|
|
111
117
|
)
|
|
112
118
|
}
|
|
113
119
|
|
|
120
|
+
/** Whether a format version records `preparation` in place of the `sdk` marker (0.1.0.3 on, PR4). */
|
|
121
|
+
function writesPreparationMarker(version: string): boolean {
|
|
122
|
+
return (
|
|
123
|
+
compareShardfileVersions(version, SHARDFILE_VERSION_PREPARATION) >= ZERO
|
|
124
|
+
)
|
|
125
|
+
}
|
|
126
|
+
|
|
114
127
|
/** A copy of a JSON object without `keys`; anything else as it is. */
|
|
115
128
|
function withoutKeys(value: unknown, keys: readonly string[]): unknown {
|
|
116
129
|
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
@@ -125,11 +138,16 @@ function withoutKeys(value: unknown, keys: readonly string[]): unknown {
|
|
|
125
138
|
|
|
126
139
|
/** The rows `outputIndexEnvelope` returns: the writer's own rows, typed so it keeps reading them, with `version` and
|
|
127
140
|
* `schemas` possibly gone and `formatVersion` possibly the version string. */
|
|
128
|
-
type IndexEnvelope<Rows> = Omit<
|
|
141
|
+
type IndexEnvelope<Rows> = Omit<
|
|
142
|
+
Rows,
|
|
143
|
+
'formatVersion' | 'schemas' | 'version' | 'sdk'
|
|
144
|
+
> &
|
|
129
145
|
Readonly<{
|
|
130
146
|
formatVersion: unknown
|
|
131
147
|
version?: unknown
|
|
132
148
|
schemas?: unknown
|
|
149
|
+
sdk?: unknown
|
|
150
|
+
preparation?: unknown
|
|
133
151
|
}>
|
|
134
152
|
|
|
135
153
|
/** SHARD-COMPAT CP14: writers build the legacy `shard.json` rows (`formatVersion: 2`, `version`, the always-empty lists)
|
|
@@ -149,6 +167,15 @@ function outputIndexEnvelope<Rows extends Readonly<Record<string, unknown>>>(
|
|
|
149
167
|
formatVersion: version,
|
|
150
168
|
runtime: withoutKeys(rest['runtime'], ['files', 'lines', 'trust']),
|
|
151
169
|
}
|
|
170
|
+
// SHARD-COMPAT PR4: from 0.1.0.3 the `sdk` marker goes; a prepared writer's `'0.3'` becomes the spec version it
|
|
171
|
+
// meant, unless the writer already names one in `preparation`.
|
|
172
|
+
if (typeof version === 'string' && writesPreparationMarker(version)) {
|
|
173
|
+
const { sdk } = envelope
|
|
174
|
+
Reflect.deleteProperty(envelope, 'sdk')
|
|
175
|
+
if (sdk === PREPARED_SDK && envelope['preparation'] === undefined) {
|
|
176
|
+
envelope['preparation'] = LEGACY_PREPARATION_SPEC
|
|
177
|
+
}
|
|
178
|
+
}
|
|
152
179
|
// oxlint-disable-next-line typescript/no-unsafe-type-assertion -- the writer's own rows; only envelope fields change
|
|
153
180
|
return envelope as IndexEnvelope<Rows>
|
|
154
181
|
}
|
|
@@ -165,6 +192,8 @@ export {
|
|
|
165
192
|
type IndexFormatVersion,
|
|
166
193
|
shardfileFormatOf,
|
|
167
194
|
writesIndexFormatVersion,
|
|
195
|
+
writesPreparationMarker,
|
|
196
|
+
SHARDFILE_VERSION_PREPARATION,
|
|
168
197
|
SHARDFILE_FLOOR,
|
|
169
198
|
type ShardfileVersion,
|
|
170
199
|
type ShardfileVersionParts,
|