@estiva-app/protocol 0.61.0 → 0.62.1
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/CHANGELOG.md +27 -0
- package/README.md +15 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/testing.d.ts +70 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +203 -0
- package/dist/testing.js.map +1 -0
- package/package.json +16 -3
- package/src/index.ts +1 -1
- package/src/testing.ts +283 -0
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,33 @@ Every entry answers the wire question explicitly, including when the answer is
|
|
|
4
4
|
nothing (ADR 0002 §4b). A change to the bytes an app publishes is a MAJOR — in
|
|
5
5
|
`0.x`, a MINOR — even when no TypeScript signature moved.
|
|
6
6
|
|
|
7
|
+
## 0.62.1 — 2026-11-20
|
|
8
|
+
|
|
9
|
+
**Wire behaviour: none written; nothing new read.** Only `/testing` changes.
|
|
10
|
+
|
|
11
|
+
- `historyArb()` makes three more shapes of first record that are on the relay
|
|
12
|
+
(estiva-ship's fixture holds one of each among 184): a record that names no
|
|
13
|
+
team, one placed by `buzz-channel` alone (SPEC §7.3), and a project titled by
|
|
14
|
+
`name` rather than `title` (REW-11); `buzz-channel` on projects only. Every
|
|
15
|
+
repo's tests on it now try them. They found the list read folding no change
|
|
16
|
+
to a record that names no team (fixed in interop 0.108.1) and Ship's own
|
|
17
|
+
read deleting one (fixed in estiva-ship's TES-2 pull request, which follows).
|
|
18
|
+
|
|
19
|
+
## 0.62.0 — 2026-11-20
|
|
20
|
+
|
|
21
|
+
**Wire behaviour: none written; nothing new read.** Nothing an app publishes
|
|
22
|
+
changes; the main entry point is unchanged.
|
|
23
|
+
|
|
24
|
+
- A second entry point, `@estiva-app/protocol/testing`, for tests that try
|
|
25
|
+
thousands of inputs: `historyArb()` makes up histories of projects, issues
|
|
26
|
+
and documents (two versions of a first record, changes of one field or
|
|
27
|
+
several, with and without a trusted `ts`, many in the same second, some from
|
|
28
|
+
outside the file's team or about another file, members joining and leaving,
|
|
29
|
+
comments), `deliveryArb(events)` hands them back in any order with some
|
|
30
|
+
twice, and `runSettings(n)` reads `FC_SEED` and `FC_RUNS`. It needs
|
|
31
|
+
`fast-check`, now an optional peer dependency; the main entry point never
|
|
32
|
+
imports it. Shapes from estiva-ship `conformance/fold-fixture.json`.
|
|
33
|
+
|
|
7
34
|
## 0.61.0 — 2026-11-18
|
|
8
35
|
|
|
9
36
|
**Wire behaviour: none written; nothing new read** (PROD-5; record
|
package/README.md
CHANGED
|
@@ -143,6 +143,21 @@ property this package can have while it depends on `@noble/*`. `TextEncoder`,
|
|
|
143
143
|
`TextDecoder` and `URL` are WHATWG universals present in every runtime the suite
|
|
144
144
|
targets, and that is the line.
|
|
145
145
|
|
|
146
|
+
## Made-up histories for tests: `@estiva-app/protocol/testing`
|
|
147
|
+
|
|
148
|
+
Tests that try thousands of inputs import one maker of random file histories
|
|
149
|
+
rather than each repo writing its own: `historyArb()` makes projects, issues and
|
|
150
|
+
documents and the changes people made to them (renamed, moved, a status set,
|
|
151
|
+
assigned, archived, deleted, a member added or leaving, by several people, many
|
|
152
|
+
in the same second, some outside the file's team), in the shapes on the relay
|
|
153
|
+
today. `deliveryArb(events)` hands the same events back in any order, some of
|
|
154
|
+
them twice. `runSettings(n)` reads `FC_SEED` and `FC_RUNS`, so a pull request
|
|
155
|
+
runs a fixed seed and a merge to `main` a fresh one, and a printed seed replays
|
|
156
|
+
a failure.
|
|
157
|
+
|
|
158
|
+
It needs [fast-check](https://fast-check.dev), an optional peer: install it as a
|
|
159
|
+
devDependency where the tests are. The main entry point never imports it.
|
|
160
|
+
|
|
146
161
|
## Consumers
|
|
147
162
|
|
|
148
163
|
Peek, Ship and `estiva-agent` — see [CONSUMERS.md](../../CONSUMERS.md). A
|
package/dist/index.d.ts
CHANGED
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
/** Bumped by hand with the version in package.json — `test/version.test.ts`
|
|
47
47
|
* pins the two together. It exists so "the upgrade reached the app" can be
|
|
48
48
|
* checked by grepping a built bundle rather than by trusting a lockfile. */
|
|
49
|
-
export declare const PROTOCOL_VERSION = "0.
|
|
49
|
+
export declare const PROTOCOL_VERSION = "0.62.1";
|
|
50
50
|
export { type NostrTag, type UnsignedEvent, type SignedEvent, type Authored, type Profile, type ThreadRef, type ChannelVisibility, type ChannelKind, type MemberRole, type FolderOp, type Label, type ResolutionAction, KIND, MAX_EMOJI_CHARS, MAX_MESSAGE_BYTES, MAX_MENTIONS, MAX_DM_OTHERS, MAX_RATIONALE_BYTES, RELAY_AUTH_TOLERANCE_SECS, ASSERTION_SUBTYPE, computeEventId, toNostrSeconds, canonicalChannelName, threadTags, addr, relayAuthUrl, buildProfile, parseProfile, buildCreateChannel, buildDeleteChannel, buildEditChannelMetadata, buildFolderCommand, buildAddMember, buildJoinGroup, buildLeaveGroup, buildDmOpen, buildDmHide, buildReaction, effectiveAuthor, needsRelayKey, RELAY_KEY_FILTER, buildDeletion, buildEdit, buildMessage, buildResolution, buildBareFile, buildDocument, buildHighlight, buildUnsignedRelayAuthEvent, } from './events.js';
|
|
51
51
|
export { type AddressPointer, type EventPointer, encodeNevent, decodeNevent, convertBits, bech32Encode, bech32Decode, encodeNaddr, decodeNaddr, pointerToAddress, addressToPointer, addrToNaddr, naddrToAddr, referenceToPointer, NADDR_RE, findNaddrs, stripNaddrs, encodeNpub, decodeNpub, NOSTR_URI_RE, findNostrUris, } from './nip19.js';
|
|
52
52
|
export { type AuthEventArgs, TIMESTAMP_TOLERANCE_SECS, normalizeUrl, buildUnsignedAuthEvent, base64, authorizationHeaderFor, authorizationHeader, } from './nip98.js';
|
package/dist/index.js
CHANGED
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
/** Bumped by hand with the version in package.json — `test/version.test.ts`
|
|
47
47
|
* pins the two together. It exists so "the upgrade reached the app" can be
|
|
48
48
|
* checked by grepping a built bundle rather than by trusting a lockfile. */
|
|
49
|
-
export const PROTOCOL_VERSION = '0.
|
|
49
|
+
export const PROTOCOL_VERSION = '0.62.1';
|
|
50
50
|
export {
|
|
51
51
|
// constants
|
|
52
52
|
KIND, MAX_EMOJI_CHARS, MAX_MESSAGE_BYTES, MAX_MENTIONS, MAX_DM_OTHERS, MAX_RATIONALE_BYTES, RELAY_AUTH_TOLERANCE_SECS, ASSERTION_SUBTYPE,
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@estiva-app/protocol/testing` — made-up histories of files, for tests that
|
|
3
|
+
* try thousands of inputs (fast-check). Test code only: it needs `fast-check`,
|
|
4
|
+
* which this package lists as an optional peer, never as a dependency.
|
|
5
|
+
*
|
|
6
|
+
* A history is what a reader can be handed for a few files: their first
|
|
7
|
+
* records (sometimes two versions of one), the changes people made to them
|
|
8
|
+
* (`kind:1851`, one field or several, with or without a trusted `ts`, some in
|
|
9
|
+
* the same second, some by people outside the file's team) and comments on
|
|
10
|
+
* them. The shapes are the ones on the relay today (estiva-ship
|
|
11
|
+
* `conformance/fold-fixture.json`, 20 Nov 2026), so every repo's tests share
|
|
12
|
+
* one idea of what a history can be.
|
|
13
|
+
*
|
|
14
|
+
* One maker, many repos: Ship, Peek and Leaf import it rather than copy it.
|
|
15
|
+
*/
|
|
16
|
+
import fc from 'fast-check';
|
|
17
|
+
import type { SignedEvent } from './events.js';
|
|
18
|
+
export declare const KIND_PROJECT = 30850;
|
|
19
|
+
export declare const KIND_ISSUE = 30851;
|
|
20
|
+
export declare const KIND_DOCUMENT = 30842;
|
|
21
|
+
export declare const KIND_CHANGE = 1851;
|
|
22
|
+
export declare const KIND_COMMENT = 1111;
|
|
23
|
+
/** What {@link historyArb} makes. */
|
|
24
|
+
export interface History {
|
|
25
|
+
/** Every event, in the order they were made up — never the order to read them in. */
|
|
26
|
+
events: SignedEvent[];
|
|
27
|
+
/** Each file's address, `<kind>:<pubkey>:<d>`. */
|
|
28
|
+
files: string[];
|
|
29
|
+
/** The people who wrote something. */
|
|
30
|
+
people: string[];
|
|
31
|
+
/** The teams (Folders) the files are filed in. */
|
|
32
|
+
teams: string[];
|
|
33
|
+
}
|
|
34
|
+
export interface HistoryOptions {
|
|
35
|
+
/** How many people write (default 3). */
|
|
36
|
+
people?: number;
|
|
37
|
+
/** At most this many changes (default 24). */
|
|
38
|
+
maxChanges?: number;
|
|
39
|
+
/** At most this many comments (default 4). */
|
|
40
|
+
maxComments?: number;
|
|
41
|
+
/** Give some files an id with a colon in it (default false: today's apps mint UUIDs). */
|
|
42
|
+
idsWithColons?: boolean;
|
|
43
|
+
}
|
|
44
|
+
/** The second every history starts at; changes land within a few seconds of it, so ties are common. */
|
|
45
|
+
export declare const HISTORY_EPOCH = 1763000000;
|
|
46
|
+
/** A 64-character lowercase hex string: an event id or a pubkey. */
|
|
47
|
+
export declare const hex64Arb: () => fc.Arbitrary<string>;
|
|
48
|
+
/**
|
|
49
|
+
* A made-up history of a few projects, issues and documents and the changes
|
|
50
|
+
* made to them. Shrinks toward fewer files, fewer changes and earlier seconds.
|
|
51
|
+
*/
|
|
52
|
+
export declare function historyArb(options?: HistoryOptions): fc.Arbitrary<History>;
|
|
53
|
+
/**
|
|
54
|
+
* The same events as a reader might be handed them: in any order, some of them
|
|
55
|
+
* twice (each repeat a copy, as a second relay answer would be).
|
|
56
|
+
*/
|
|
57
|
+
export declare function deliveryArb<T>(events: readonly T[]): fc.Arbitrary<T[]>;
|
|
58
|
+
/** The starting number a pull request runs with: the same inputs on every run. */
|
|
59
|
+
export declare const FIXED_SEED = 20261120;
|
|
60
|
+
/**
|
|
61
|
+
* The run's settings, from the environment: `FC_SEED` replays a run (CI sets a
|
|
62
|
+
* fresh one on each merge to `main` and prints it), `FC_RUNS` sets how many
|
|
63
|
+
* inputs each rule tries. Without them a run is the pull request's: the fixed
|
|
64
|
+
* seed and `defaultRuns`.
|
|
65
|
+
*/
|
|
66
|
+
export declare function runSettings(defaultRuns: number, env?: Record<string, string | undefined>): {
|
|
67
|
+
seed: number;
|
|
68
|
+
numRuns: number;
|
|
69
|
+
};
|
|
70
|
+
//# sourceMappingURL=testing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,MAAM,YAAY,CAAA;AAC3B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAE9C,eAAO,MAAM,YAAY,QAAQ,CAAA;AACjC,eAAO,MAAM,UAAU,QAAQ,CAAA;AAC/B,eAAO,MAAM,aAAa,QAAQ,CAAA;AAClC,eAAO,MAAM,WAAW,OAAO,CAAA;AAC/B,eAAO,MAAM,YAAY,OAAO,CAAA;AAEhC,qCAAqC;AACrC,MAAM,WAAW,OAAO;IACtB,qFAAqF;IACrF,MAAM,EAAE,WAAW,EAAE,CAAA;IACrB,kDAAkD;IAClD,KAAK,EAAE,MAAM,EAAE,CAAA;IACf,sCAAsC;IACtC,MAAM,EAAE,MAAM,EAAE,CAAA;IAChB,kDAAkD;IAClD,KAAK,EAAE,MAAM,EAAE,CAAA;CAChB;AAED,MAAM,WAAW,cAAc;IAC7B,yCAAyC;IACzC,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,8CAA8C;IAC9C,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,8CAA8C;IAC9C,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,yFAAyF;IACzF,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB;AAED,uGAAuG;AACvG,eAAO,MAAM,aAAa,aAAgB,CAAA;AAG1C,oEAAoE;AACpE,eAAO,MAAM,QAAQ,QAAO,EAAE,CAAC,SAAS,CAAC,MAAM,CAA+E,CAAA;AAyC9H;;;GAGG;AACH,wBAAgB,UAAU,CAAC,OAAO,GAAE,cAAmB,GAAG,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC,CA0C9E;AA8GD;;;GAGG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAQtE;AAED,kFAAkF;AAClF,eAAO,MAAM,UAAU,WAAa,CAAA;AAEpC;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,WAAW,EAAE,MAAM,EAAE,GAAG,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAgB,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAM1I"}
|
package/dist/testing.js
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@estiva-app/protocol/testing` — made-up histories of files, for tests that
|
|
3
|
+
* try thousands of inputs (fast-check). Test code only: it needs `fast-check`,
|
|
4
|
+
* which this package lists as an optional peer, never as a dependency.
|
|
5
|
+
*
|
|
6
|
+
* A history is what a reader can be handed for a few files: their first
|
|
7
|
+
* records (sometimes two versions of one), the changes people made to them
|
|
8
|
+
* (`kind:1851`, one field or several, with or without a trusted `ts`, some in
|
|
9
|
+
* the same second, some by people outside the file's team) and comments on
|
|
10
|
+
* them. The shapes are the ones on the relay today (estiva-ship
|
|
11
|
+
* `conformance/fold-fixture.json`, 20 Nov 2026), so every repo's tests share
|
|
12
|
+
* one idea of what a history can be.
|
|
13
|
+
*
|
|
14
|
+
* One maker, many repos: Ship, Peek and Leaf import it rather than copy it.
|
|
15
|
+
*/
|
|
16
|
+
import fc from 'fast-check';
|
|
17
|
+
export const KIND_PROJECT = 30850;
|
|
18
|
+
export const KIND_ISSUE = 30851;
|
|
19
|
+
export const KIND_DOCUMENT = 30842;
|
|
20
|
+
export const KIND_CHANGE = 1851;
|
|
21
|
+
export const KIND_COMMENT = 1111;
|
|
22
|
+
/** The second every history starts at; changes land within a few seconds of it, so ties are common. */
|
|
23
|
+
export const HISTORY_EPOCH = 1_763_000_000;
|
|
24
|
+
const HEX = '0123456789abcdef'.split('');
|
|
25
|
+
/** A 64-character lowercase hex string: an event id or a pubkey. */
|
|
26
|
+
export const hex64Arb = () => fc.string({ unit: fc.constantFrom(...HEX), minLength: 64, maxLength: 64 });
|
|
27
|
+
const STATUSES = ['todo', 'in_progress', 'done', 'cancelled'];
|
|
28
|
+
const TITLES = ['Payments', 'Billing', 'Renamed', 'Untitled', 'Launch plan', ''];
|
|
29
|
+
const FIELDS = ['title', 'status', 'summary', 'assignee', 'archived', 'deleted', 'project', 'member'];
|
|
30
|
+
/**
|
|
31
|
+
* A made-up history of a few projects, issues and documents and the changes
|
|
32
|
+
* made to them. Shrinks toward fewer files, fewer changes and earlier seconds.
|
|
33
|
+
*/
|
|
34
|
+
export function historyArb(options = {}) {
|
|
35
|
+
const peopleCount = options.people ?? 3;
|
|
36
|
+
const rootArb = (kind) => fc.record({
|
|
37
|
+
kind: fc.constant(kind),
|
|
38
|
+
author: fc.nat(peopleCount - 1),
|
|
39
|
+
team: fc.nat(1),
|
|
40
|
+
// `buzz-channel` is a project's placement only (SPEC §7.3).
|
|
41
|
+
placement: fc.oneof({ weight: 8, arbitrary: fc.constant('h') }, { weight: 1, arbitrary: fc.constant(kind === KIND_PROJECT ? 'buzz-channel' : 'h') }, { weight: 1, arbitrary: fc.constant('none') }),
|
|
42
|
+
nameTag: kind === KIND_PROJECT ? fc.boolean() : fc.constant(false),
|
|
43
|
+
colon: options.idsWithColons ? fc.boolean() : fc.constant(false),
|
|
44
|
+
title: fc.constantFrom(...TITLES),
|
|
45
|
+
second: fc.option(fc.record({ after: fc.nat(2), title: fc.constantFrom(...TITLES) }), { freq: 4 }),
|
|
46
|
+
});
|
|
47
|
+
const changeArb = fc.record({
|
|
48
|
+
file: fc.nat(7),
|
|
49
|
+
author: fc.nat(peopleCount - 1),
|
|
50
|
+
at: fc.nat(4),
|
|
51
|
+
ts: fc.oneof(fc.constant(null), fc.constantFrom(0, 500, 999), fc.constant('untrusted')),
|
|
52
|
+
sets: fc.array(fc.record({ field: fc.constantFrom(...FIELDS), value: fc.nat(7) }), { minLength: 1, maxLength: 2 }),
|
|
53
|
+
O: fc.constantFrom('own', 'own', 'none', 'other'),
|
|
54
|
+
inOwnTeam: fc.oneof({ weight: 9, arbitrary: fc.constant(true) }, { weight: 1, arbitrary: fc.constant(false) }),
|
|
55
|
+
});
|
|
56
|
+
const plan = fc.record({
|
|
57
|
+
people: fc.uniqueArray(hex64Arb(), { minLength: peopleCount, maxLength: peopleCount }),
|
|
58
|
+
teams: fc.uniqueArray(fc.uuid({ version: 4 }), { minLength: 2, maxLength: 2 }),
|
|
59
|
+
projects: fc.array(rootArb(KIND_PROJECT), { minLength: 1, maxLength: 2 }),
|
|
60
|
+
issues: fc.array(rootArb(KIND_ISSUE), { maxLength: 3 }),
|
|
61
|
+
documents: fc.array(rootArb(KIND_DOCUMENT), { maxLength: 2 }),
|
|
62
|
+
fileIds: fc.uniqueArray(fc.uuid({ version: 4 }), { minLength: 8, maxLength: 8 }),
|
|
63
|
+
changes: fc.array(changeArb, { maxLength: options.maxChanges ?? 24 }),
|
|
64
|
+
comments: fc.array(fc.record({ file: fc.nat(7), author: fc.nat(peopleCount - 1), at: fc.nat(4) }), { maxLength: options.maxComments ?? 4 }),
|
|
65
|
+
});
|
|
66
|
+
return plan.chain((p) => {
|
|
67
|
+
const count = p.projects.length + p.issues.length + p.documents.length + p.changes.length + p.comments.length;
|
|
68
|
+
// Twice what is needed: a second version of a root takes one each.
|
|
69
|
+
return fc.uniqueArray(hex64Arb(), { minLength: count * 2, maxLength: count * 2 }).map((ids) => build(p, ids));
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
function build(p, ids) {
|
|
73
|
+
let next = 0;
|
|
74
|
+
const id = () => ids[next++];
|
|
75
|
+
const events = [];
|
|
76
|
+
const files = [];
|
|
77
|
+
const roots = [...p.projects, ...p.issues, ...p.documents];
|
|
78
|
+
roots.forEach((root, i) => {
|
|
79
|
+
const d = root.colon ? `x:${p.fileIds[i]}` : p.fileIds[i];
|
|
80
|
+
const pubkey = p.people[root.author];
|
|
81
|
+
const team = p.teams[root.team];
|
|
82
|
+
const address = `${root.kind}:${pubkey}:${d}`;
|
|
83
|
+
// An issue is filed under the first project; a project and a document stand alone.
|
|
84
|
+
const parent = root.kind === KIND_ISSUE ? files[0]?.address : undefined;
|
|
85
|
+
const placed = root.placement === 'none' ? [] : [[root.placement, team]];
|
|
86
|
+
const tags = (title) => [['d', d], [root.nameTag ? 'name' : 'title', title], ...placed, ...(parent ? [['a', parent]] : [])];
|
|
87
|
+
events.push({ id: id(), pubkey, created_at: HISTORY_EPOCH, kind: root.kind, tags: tags(root.title), content: '', sig: '' });
|
|
88
|
+
if (root.second) {
|
|
89
|
+
events.push({ id: id(), pubkey, created_at: HISTORY_EPOCH + root.second.after, kind: root.kind, tags: tags(root.second.title), content: '', sig: '' });
|
|
90
|
+
}
|
|
91
|
+
files.push({ address, d, kind: root.kind, team, author: pubkey });
|
|
92
|
+
});
|
|
93
|
+
const projects = files.filter((f) => f.kind === KIND_PROJECT);
|
|
94
|
+
for (const change of p.changes) {
|
|
95
|
+
const file = files[change.file % files.length];
|
|
96
|
+
const pubkey = p.people[change.author];
|
|
97
|
+
const created_at = HISTORY_EPOCH + change.at;
|
|
98
|
+
const set = change.sets
|
|
99
|
+
.map(({ field, value }) => setting(field, value, file, p.people, projects))
|
|
100
|
+
.filter((s) => s !== undefined);
|
|
101
|
+
// One field a change sets at most once; a several-field change never names a member (§11.8).
|
|
102
|
+
const unique = [...new Map(set.map((s) => [s[0], s])).values()];
|
|
103
|
+
const fields = unique.length > 1 ? unique.filter(([f]) => !f.startsWith('member:')) : unique;
|
|
104
|
+
if (!fields.length)
|
|
105
|
+
continue;
|
|
106
|
+
const tags = [['a', file.address]];
|
|
107
|
+
if (change.O === 'own')
|
|
108
|
+
tags.push(['O', file.d]);
|
|
109
|
+
// At most seven files, so the eighth id is never one of theirs.
|
|
110
|
+
else if (change.O === 'other')
|
|
111
|
+
tags.push(['O', p.fileIds[7]]);
|
|
112
|
+
tags.push(['h', change.inOwnTeam ? file.team : p.teams.find((t) => t !== file.team)]);
|
|
113
|
+
if (fields.length === 1)
|
|
114
|
+
tags.push(['field', fields[0][0]], ['value', fields[0][1]]);
|
|
115
|
+
else
|
|
116
|
+
for (const [f, v] of fields)
|
|
117
|
+
tags.push(['set', f, v]);
|
|
118
|
+
// A change names the person it is about in `p`, as membership's filters find it (§11.8).
|
|
119
|
+
for (const [f, v] of fields) {
|
|
120
|
+
if (f === 'assignee' && v)
|
|
121
|
+
tags.push(['p', v]);
|
|
122
|
+
else if (f.startsWith('member:'))
|
|
123
|
+
tags.push(['p', f.slice('member:'.length)]);
|
|
124
|
+
}
|
|
125
|
+
if (change.ts === 'untrusted')
|
|
126
|
+
tags.push(['ts', String((created_at + 7) * 1000)]);
|
|
127
|
+
else if (change.ts !== null)
|
|
128
|
+
tags.push(['ts', String(created_at * 1000 + change.ts)]);
|
|
129
|
+
events.push({ id: id(), pubkey, created_at, kind: KIND_CHANGE, tags, content: '', sig: '' });
|
|
130
|
+
}
|
|
131
|
+
for (const comment of p.comments) {
|
|
132
|
+
const file = files[comment.file % files.length];
|
|
133
|
+
events.push({
|
|
134
|
+
id: id(),
|
|
135
|
+
pubkey: p.people[comment.author],
|
|
136
|
+
created_at: HISTORY_EPOCH + comment.at,
|
|
137
|
+
kind: KIND_COMMENT,
|
|
138
|
+
tags: [['A', file.address], ['K', String(file.kind)], ['a', file.address], ['k', String(file.kind)], ['h', file.team]],
|
|
139
|
+
content: 'A comment',
|
|
140
|
+
sig: '',
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
return { events, files: files.map((f) => f.address), people: p.people, teams: p.teams };
|
|
144
|
+
}
|
|
145
|
+
/** One field a change sets and its value, or none where the field does not fit the file. */
|
|
146
|
+
function setting(field, n, file, people, projects) {
|
|
147
|
+
switch (field) {
|
|
148
|
+
case 'title':
|
|
149
|
+
return ['title', TITLES[n % TITLES.length]];
|
|
150
|
+
case 'status':
|
|
151
|
+
return file.kind === KIND_DOCUMENT ? undefined : ['status', STATUSES[n % STATUSES.length]];
|
|
152
|
+
case 'summary':
|
|
153
|
+
return ['summary', n % 3 === 0 ? '' : `Summary ${n}`];
|
|
154
|
+
case 'assignee':
|
|
155
|
+
return file.kind !== KIND_ISSUE ? undefined : ['assignee', n % 4 === 3 ? '' : people[n % people.length]];
|
|
156
|
+
case 'archived':
|
|
157
|
+
return ['archived', n % 2 ? 'true' : ''];
|
|
158
|
+
case 'deleted':
|
|
159
|
+
return ['deleted', n % 2 ? 'true' : ''];
|
|
160
|
+
case 'project': {
|
|
161
|
+
// A move: an issue's parent becomes another project.
|
|
162
|
+
if (file.kind !== KIND_ISSUE || !projects.length)
|
|
163
|
+
return undefined;
|
|
164
|
+
return ['project', projects[n % projects.length].address];
|
|
165
|
+
}
|
|
166
|
+
case 'member':
|
|
167
|
+
return [`member:${people[n % people.length]}`, n % 2 ? 'true' : 'false'];
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* The same events as a reader might be handed them: in any order, some of them
|
|
172
|
+
* twice (each repeat a copy, as a second relay answer would be).
|
|
173
|
+
*/
|
|
174
|
+
export function deliveryArb(events) {
|
|
175
|
+
const n = events.length;
|
|
176
|
+
return fc
|
|
177
|
+
.tuple(fc.shuffledSubarray([...events], { minLength: n, maxLength: n }), fc.subarray([...events]))
|
|
178
|
+
.chain(([all, twice]) => {
|
|
179
|
+
const pool = [...all, ...twice.map((e) => JSON.parse(JSON.stringify(e)))];
|
|
180
|
+
return fc.shuffledSubarray(pool, { minLength: pool.length, maxLength: pool.length });
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
/** The starting number a pull request runs with: the same inputs on every run. */
|
|
184
|
+
export const FIXED_SEED = 20_261_120;
|
|
185
|
+
/**
|
|
186
|
+
* The run's settings, from the environment: `FC_SEED` replays a run (CI sets a
|
|
187
|
+
* fresh one on each merge to `main` and prints it), `FC_RUNS` sets how many
|
|
188
|
+
* inputs each rule tries. Without them a run is the pull request's: the fixed
|
|
189
|
+
* seed and `defaultRuns`.
|
|
190
|
+
*/
|
|
191
|
+
export function runSettings(defaultRuns, env = processEnv()) {
|
|
192
|
+
const seed = env.FC_SEED ? Number(env.FC_SEED) : FIXED_SEED;
|
|
193
|
+
const runs = env.FC_RUNS ? Number(env.FC_RUNS) : defaultRuns;
|
|
194
|
+
if (!Number.isSafeInteger(seed))
|
|
195
|
+
throw new Error(`FC_SEED is not a whole number: ${env.FC_SEED}`);
|
|
196
|
+
if (!Number.isSafeInteger(runs) || runs < 1)
|
|
197
|
+
throw new Error(`FC_RUNS is not a positive whole number: ${env.FC_RUNS}`);
|
|
198
|
+
return { seed, numRuns: runs };
|
|
199
|
+
}
|
|
200
|
+
function processEnv() {
|
|
201
|
+
return globalThis.process?.env ?? {};
|
|
202
|
+
}
|
|
203
|
+
//# sourceMappingURL=testing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testing.js","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,MAAM,YAAY,CAAA;AAG3B,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,CAAA;AACjC,MAAM,CAAC,MAAM,UAAU,GAAG,KAAK,CAAA;AAC/B,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,CAAA;AAClC,MAAM,CAAC,MAAM,WAAW,GAAG,IAAI,CAAA;AAC/B,MAAM,CAAC,MAAM,YAAY,GAAG,IAAI,CAAA;AAyBhC,uGAAuG;AACvG,MAAM,CAAC,MAAM,aAAa,GAAG,aAAa,CAAA;AAE1C,MAAM,GAAG,GAAG,kBAAkB,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;AACxC,oEAAoE;AACpE,MAAM,CAAC,MAAM,QAAQ,GAAG,GAAyB,EAAE,CAAC,EAAE,CAAC,MAAM,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,IAAI,GAAG,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,WAAW,CAAA;IAC5D,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,kCAAkC,GAAG,CAAC,OAAO,EAAE,CAAC,CAAA;IACjG,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,IAAI,GAAG,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,2CAA2C,GAAG,CAAC,OAAO,EAAE,CAAC,CAAA;IACtH,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAA;AAChC,CAAC;AAED,SAAS,UAAU;IACjB,OAAQ,UAAyE,CAAC,OAAO,EAAE,GAAG,IAAI,EAAE,CAAA;AACtG,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@estiva-app/protocol",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.62.1",
|
|
4
4
|
"description": "The Estiva wire format: Buzz-shaped Nostr event builders, NIP-01 ids, NIP-19 naddr, NIP-98 HTTP auth, and the relay clients. Speaks the protocol; interprets nothing.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -9,6 +9,10 @@
|
|
|
9
9
|
"types": "./dist/index.d.ts",
|
|
10
10
|
"default": "./dist/index.js"
|
|
11
11
|
},
|
|
12
|
+
"./testing": {
|
|
13
|
+
"types": "./dist/testing.d.ts",
|
|
14
|
+
"default": "./dist/testing.js"
|
|
15
|
+
},
|
|
12
16
|
"./package.json": "./package.json"
|
|
13
17
|
},
|
|
14
18
|
"main": "./dist/index.js",
|
|
@@ -51,9 +55,18 @@
|
|
|
51
55
|
"@noble/curves": "^1.9.2",
|
|
52
56
|
"@noble/hashes": "^1.8.0"
|
|
53
57
|
},
|
|
58
|
+
"peerDependencies": {
|
|
59
|
+
"fast-check": "^4.10.2"
|
|
60
|
+
},
|
|
61
|
+
"peerDependenciesMeta": {
|
|
62
|
+
"fast-check": {
|
|
63
|
+
"optional": true
|
|
64
|
+
}
|
|
65
|
+
},
|
|
54
66
|
"devDependencies": {
|
|
67
|
+
"@types/node": "^24.13.3",
|
|
68
|
+
"fast-check": "4.10.2",
|
|
55
69
|
"nostr-tools": "^2.25.0",
|
|
56
|
-
"typescript": "~5.9.3"
|
|
57
|
-
"@types/node": "^24.13.3"
|
|
70
|
+
"typescript": "~5.9.3"
|
|
58
71
|
}
|
|
59
72
|
}
|
package/src/index.ts
CHANGED
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
/** Bumped by hand with the version in package.json — `test/version.test.ts`
|
|
48
48
|
* pins the two together. It exists so "the upgrade reached the app" can be
|
|
49
49
|
* checked by grepping a built bundle rather than by trusting a lockfile. */
|
|
50
|
-
export const PROTOCOL_VERSION = '0.
|
|
50
|
+
export const PROTOCOL_VERSION = '0.62.1'
|
|
51
51
|
|
|
52
52
|
export {
|
|
53
53
|
// types
|
package/src/testing.ts
ADDED
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@estiva-app/protocol/testing` — made-up histories of files, for tests that
|
|
3
|
+
* try thousands of inputs (fast-check). Test code only: it needs `fast-check`,
|
|
4
|
+
* which this package lists as an optional peer, never as a dependency.
|
|
5
|
+
*
|
|
6
|
+
* A history is what a reader can be handed for a few files: their first
|
|
7
|
+
* records (sometimes two versions of one), the changes people made to them
|
|
8
|
+
* (`kind:1851`, one field or several, with or without a trusted `ts`, some in
|
|
9
|
+
* the same second, some by people outside the file's team) and comments on
|
|
10
|
+
* them. The shapes are the ones on the relay today (estiva-ship
|
|
11
|
+
* `conformance/fold-fixture.json`, 20 Nov 2026), so every repo's tests share
|
|
12
|
+
* one idea of what a history can be.
|
|
13
|
+
*
|
|
14
|
+
* One maker, many repos: Ship, Peek and Leaf import it rather than copy it.
|
|
15
|
+
*/
|
|
16
|
+
import fc from 'fast-check'
|
|
17
|
+
import type { SignedEvent } from './events.js'
|
|
18
|
+
|
|
19
|
+
export const KIND_PROJECT = 30850
|
|
20
|
+
export const KIND_ISSUE = 30851
|
|
21
|
+
export const KIND_DOCUMENT = 30842
|
|
22
|
+
export const KIND_CHANGE = 1851
|
|
23
|
+
export const KIND_COMMENT = 1111
|
|
24
|
+
|
|
25
|
+
/** What {@link historyArb} makes. */
|
|
26
|
+
export interface History {
|
|
27
|
+
/** Every event, in the order they were made up — never the order to read them in. */
|
|
28
|
+
events: SignedEvent[]
|
|
29
|
+
/** Each file's address, `<kind>:<pubkey>:<d>`. */
|
|
30
|
+
files: string[]
|
|
31
|
+
/** The people who wrote something. */
|
|
32
|
+
people: string[]
|
|
33
|
+
/** The teams (Folders) the files are filed in. */
|
|
34
|
+
teams: string[]
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface HistoryOptions {
|
|
38
|
+
/** How many people write (default 3). */
|
|
39
|
+
people?: number
|
|
40
|
+
/** At most this many changes (default 24). */
|
|
41
|
+
maxChanges?: number
|
|
42
|
+
/** At most this many comments (default 4). */
|
|
43
|
+
maxComments?: number
|
|
44
|
+
/** Give some files an id with a colon in it (default false: today's apps mint UUIDs). */
|
|
45
|
+
idsWithColons?: boolean
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** The second every history starts at; changes land within a few seconds of it, so ties are common. */
|
|
49
|
+
export const HISTORY_EPOCH = 1_763_000_000
|
|
50
|
+
|
|
51
|
+
const HEX = '0123456789abcdef'.split('')
|
|
52
|
+
/** A 64-character lowercase hex string: an event id or a pubkey. */
|
|
53
|
+
export const hex64Arb = (): fc.Arbitrary<string> => fc.string({ unit: fc.constantFrom(...HEX), minLength: 64, maxLength: 64 })
|
|
54
|
+
|
|
55
|
+
const STATUSES = ['todo', 'in_progress', 'done', 'cancelled']
|
|
56
|
+
const TITLES = ['Payments', 'Billing', 'Renamed', 'Untitled', 'Launch plan', '']
|
|
57
|
+
|
|
58
|
+
type FileKind = typeof KIND_PROJECT | typeof KIND_ISSUE | typeof KIND_DOCUMENT
|
|
59
|
+
|
|
60
|
+
interface RootPlan {
|
|
61
|
+
kind: FileKind
|
|
62
|
+
author: number
|
|
63
|
+
team: number
|
|
64
|
+
/**
|
|
65
|
+
* How the first record names its team: `h` (most), Ship's global
|
|
66
|
+
* `buzz-channel` (SPEC §7.3), or not at all — all three are on the relay
|
|
67
|
+
* (estiva-ship's fixture: 1 of 184 records each for the last two).
|
|
68
|
+
*/
|
|
69
|
+
placement: 'h' | 'buzz-channel' | 'none'
|
|
70
|
+
/** A project titled by upstream's `name` rather than `title` (REW-11); also on the relay. */
|
|
71
|
+
nameTag: boolean
|
|
72
|
+
colon: boolean
|
|
73
|
+
title: string
|
|
74
|
+
/** A second version of the first record: its offset in seconds (0 = the same second) and its title. */
|
|
75
|
+
second: { after: number; title: string } | null
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
interface ChangePlan {
|
|
79
|
+
file: number
|
|
80
|
+
author: number
|
|
81
|
+
/** Seconds after {@link HISTORY_EPOCH}. */
|
|
82
|
+
at: number
|
|
83
|
+
/** `null` for no `ts`; a millisecond within the second; or `'untrusted'`, a `ts` from another second. */
|
|
84
|
+
ts: number | 'untrusted' | null
|
|
85
|
+
sets: { field: (typeof FIELDS)[number]; value: number }[]
|
|
86
|
+
/** Carry the file's id in `O` (as writers since §6.2 do), or the id of another file, or none. */
|
|
87
|
+
O: 'own' | 'other' | 'none'
|
|
88
|
+
/** Filed in the file's own team, or in another one (which a reader must not fold). */
|
|
89
|
+
inOwnTeam: boolean
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const FIELDS = ['title', 'status', 'summary', 'assignee', 'archived', 'deleted', 'project', 'member'] as const
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* A made-up history of a few projects, issues and documents and the changes
|
|
96
|
+
* made to them. Shrinks toward fewer files, fewer changes and earlier seconds.
|
|
97
|
+
*/
|
|
98
|
+
export function historyArb(options: HistoryOptions = {}): fc.Arbitrary<History> {
|
|
99
|
+
const peopleCount = options.people ?? 3
|
|
100
|
+
const rootArb = (kind: FileKind): fc.Arbitrary<RootPlan> =>
|
|
101
|
+
fc.record({
|
|
102
|
+
kind: fc.constant(kind),
|
|
103
|
+
author: fc.nat(peopleCount - 1),
|
|
104
|
+
team: fc.nat(1),
|
|
105
|
+
// `buzz-channel` is a project's placement only (SPEC §7.3).
|
|
106
|
+
placement: fc.oneof(
|
|
107
|
+
{ weight: 8, arbitrary: fc.constant<RootPlan['placement']>('h') },
|
|
108
|
+
{ weight: 1, arbitrary: fc.constant<RootPlan['placement']>(kind === KIND_PROJECT ? 'buzz-channel' : 'h') },
|
|
109
|
+
{ weight: 1, arbitrary: fc.constant<RootPlan['placement']>('none') },
|
|
110
|
+
),
|
|
111
|
+
nameTag: kind === KIND_PROJECT ? fc.boolean() : fc.constant(false),
|
|
112
|
+
colon:options.idsWithColons ? fc.boolean() : fc.constant(false),
|
|
113
|
+
title: fc.constantFrom(...TITLES),
|
|
114
|
+
second: fc.option(fc.record({ after: fc.nat(2), title: fc.constantFrom(...TITLES) }), { freq: 4 }),
|
|
115
|
+
})
|
|
116
|
+
const changeArb: fc.Arbitrary<ChangePlan> = fc.record({
|
|
117
|
+
file: fc.nat(7),
|
|
118
|
+
author: fc.nat(peopleCount - 1),
|
|
119
|
+
at: fc.nat(4),
|
|
120
|
+
ts: fc.oneof(fc.constant(null), fc.constantFrom(0, 500, 999), fc.constant('untrusted' as const)),
|
|
121
|
+
sets: fc.array(fc.record({ field: fc.constantFrom(...FIELDS), value: fc.nat(7) }), { minLength: 1, maxLength: 2 }),
|
|
122
|
+
O: fc.constantFrom('own', 'own', 'none', 'other'),
|
|
123
|
+
inOwnTeam: fc.oneof({ weight: 9, arbitrary: fc.constant(true) }, { weight: 1, arbitrary: fc.constant(false) }),
|
|
124
|
+
})
|
|
125
|
+
const plan = fc.record({
|
|
126
|
+
people: fc.uniqueArray(hex64Arb(), { minLength: peopleCount, maxLength: peopleCount }),
|
|
127
|
+
teams: fc.uniqueArray(fc.uuid({ version: 4 }), { minLength: 2, maxLength: 2 }),
|
|
128
|
+
projects: fc.array(rootArb(KIND_PROJECT), { minLength: 1, maxLength: 2 }),
|
|
129
|
+
issues: fc.array(rootArb(KIND_ISSUE), { maxLength: 3 }),
|
|
130
|
+
documents: fc.array(rootArb(KIND_DOCUMENT), { maxLength: 2 }),
|
|
131
|
+
fileIds: fc.uniqueArray(fc.uuid({ version: 4 }), { minLength: 8, maxLength: 8 }),
|
|
132
|
+
changes: fc.array(changeArb, { maxLength: options.maxChanges ?? 24 }),
|
|
133
|
+
comments: fc.array(fc.record({ file: fc.nat(7), author: fc.nat(peopleCount - 1), at: fc.nat(4) }), { maxLength: options.maxComments ?? 4 }),
|
|
134
|
+
})
|
|
135
|
+
return plan.chain((p) => {
|
|
136
|
+
const count = p.projects.length + p.issues.length + p.documents.length + p.changes.length + p.comments.length
|
|
137
|
+
// Twice what is needed: a second version of a root takes one each.
|
|
138
|
+
return fc.uniqueArray(hex64Arb(), { minLength: count * 2, maxLength: count * 2 }).map((ids) => build(p, ids))
|
|
139
|
+
})
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
interface Plan {
|
|
143
|
+
people: string[]
|
|
144
|
+
teams: string[]
|
|
145
|
+
projects: RootPlan[]
|
|
146
|
+
issues: RootPlan[]
|
|
147
|
+
documents: RootPlan[]
|
|
148
|
+
fileIds: string[]
|
|
149
|
+
changes: ChangePlan[]
|
|
150
|
+
comments: { file: number; author: number; at: number }[]
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function build(p: Plan, ids: string[]): History {
|
|
154
|
+
let next = 0
|
|
155
|
+
const id = () => ids[next++]
|
|
156
|
+
const events: SignedEvent[] = []
|
|
157
|
+
const files: { address: string; d: string; kind: FileKind; team: string; author: string }[] = []
|
|
158
|
+
const roots = [...p.projects, ...p.issues, ...p.documents]
|
|
159
|
+
roots.forEach((root, i) => {
|
|
160
|
+
const d = root.colon ? `x:${p.fileIds[i]}` : p.fileIds[i]
|
|
161
|
+
const pubkey = p.people[root.author]
|
|
162
|
+
const team = p.teams[root.team]
|
|
163
|
+
const address = `${root.kind}:${pubkey}:${d}`
|
|
164
|
+
// An issue is filed under the first project; a project and a document stand alone.
|
|
165
|
+
const parent = root.kind === KIND_ISSUE ? files[0]?.address : undefined
|
|
166
|
+
const placed = root.placement === 'none' ? [] : [[root.placement, team]]
|
|
167
|
+
const tags = (title: string) => [['d', d], [root.nameTag ? 'name' : 'title', title], ...placed, ...(parent ? [['a', parent]] : [])]
|
|
168
|
+
events.push({ id: id(), pubkey, created_at: HISTORY_EPOCH, kind: root.kind, tags: tags(root.title), content: '', sig: '' })
|
|
169
|
+
if (root.second) {
|
|
170
|
+
events.push({ id: id(), pubkey, created_at: HISTORY_EPOCH + root.second.after, kind: root.kind, tags: tags(root.second.title), content: '', sig: '' })
|
|
171
|
+
}
|
|
172
|
+
files.push({ address, d, kind: root.kind, team, author: pubkey })
|
|
173
|
+
})
|
|
174
|
+
const projects = files.filter((f) => f.kind === KIND_PROJECT)
|
|
175
|
+
|
|
176
|
+
for (const change of p.changes) {
|
|
177
|
+
const file = files[change.file % files.length]
|
|
178
|
+
const pubkey = p.people[change.author]
|
|
179
|
+
const created_at = HISTORY_EPOCH + change.at
|
|
180
|
+
const set = change.sets
|
|
181
|
+
.map(({ field, value }) => setting(field, value, file, p.people, projects))
|
|
182
|
+
.filter((s): s is [string, string] => s !== undefined)
|
|
183
|
+
// One field a change sets at most once; a several-field change never names a member (§11.8).
|
|
184
|
+
const unique = [...new Map(set.map((s) => [s[0], s])).values()]
|
|
185
|
+
const fields = unique.length > 1 ? unique.filter(([f]) => !f.startsWith('member:')) : unique
|
|
186
|
+
if (!fields.length) continue
|
|
187
|
+
const tags: string[][] = [['a', file.address]]
|
|
188
|
+
if (change.O === 'own') tags.push(['O', file.d])
|
|
189
|
+
// At most seven files, so the eighth id is never one of theirs.
|
|
190
|
+
else if (change.O === 'other') tags.push(['O', p.fileIds[7]])
|
|
191
|
+
tags.push(['h', change.inOwnTeam ? file.team : p.teams.find((t) => t !== file.team)!])
|
|
192
|
+
if (fields.length === 1) tags.push(['field', fields[0][0]], ['value', fields[0][1]])
|
|
193
|
+
else for (const [f, v] of fields) tags.push(['set', f, v])
|
|
194
|
+
// A change names the person it is about in `p`, as membership's filters find it (§11.8).
|
|
195
|
+
for (const [f, v] of fields) {
|
|
196
|
+
if (f === 'assignee' && v) tags.push(['p', v])
|
|
197
|
+
else if (f.startsWith('member:')) tags.push(['p', f.slice('member:'.length)])
|
|
198
|
+
}
|
|
199
|
+
if (change.ts === 'untrusted') tags.push(['ts', String((created_at + 7) * 1000)])
|
|
200
|
+
else if (change.ts !== null) tags.push(['ts', String(created_at * 1000 + change.ts)])
|
|
201
|
+
events.push({ id: id(), pubkey, created_at, kind: KIND_CHANGE, tags, content: '', sig: '' })
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
for (const comment of p.comments) {
|
|
205
|
+
const file = files[comment.file % files.length]
|
|
206
|
+
events.push({
|
|
207
|
+
id: id(),
|
|
208
|
+
pubkey: p.people[comment.author],
|
|
209
|
+
created_at: HISTORY_EPOCH + comment.at,
|
|
210
|
+
kind: KIND_COMMENT,
|
|
211
|
+
tags: [['A', file.address], ['K', String(file.kind)], ['a', file.address], ['k', String(file.kind)], ['h', file.team]],
|
|
212
|
+
content: 'A comment',
|
|
213
|
+
sig: '',
|
|
214
|
+
})
|
|
215
|
+
}
|
|
216
|
+
return { events, files: files.map((f) => f.address), people: p.people, teams: p.teams }
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/** One field a change sets and its value, or none where the field does not fit the file. */
|
|
220
|
+
function setting(
|
|
221
|
+
field: (typeof FIELDS)[number],
|
|
222
|
+
n: number,
|
|
223
|
+
file: { kind: FileKind; address: string },
|
|
224
|
+
people: string[],
|
|
225
|
+
projects: { address: string }[],
|
|
226
|
+
): [string, string] | undefined {
|
|
227
|
+
switch (field) {
|
|
228
|
+
case 'title':
|
|
229
|
+
return ['title', TITLES[n % TITLES.length]]
|
|
230
|
+
case 'status':
|
|
231
|
+
return file.kind === KIND_DOCUMENT ? undefined : ['status', STATUSES[n % STATUSES.length]]
|
|
232
|
+
case 'summary':
|
|
233
|
+
return ['summary', n % 3 === 0 ? '' : `Summary ${n}`]
|
|
234
|
+
case 'assignee':
|
|
235
|
+
return file.kind !== KIND_ISSUE ? undefined : ['assignee', n % 4 === 3 ? '' : people[n % people.length]]
|
|
236
|
+
case 'archived':
|
|
237
|
+
return ['archived', n % 2 ? 'true' : '']
|
|
238
|
+
case 'deleted':
|
|
239
|
+
return ['deleted', n % 2 ? 'true' : '']
|
|
240
|
+
case 'project': {
|
|
241
|
+
// A move: an issue's parent becomes another project.
|
|
242
|
+
if (file.kind !== KIND_ISSUE || !projects.length) return undefined
|
|
243
|
+
return ['project', projects[n % projects.length].address]
|
|
244
|
+
}
|
|
245
|
+
case 'member':
|
|
246
|
+
return [`member:${people[n % people.length]}`, n % 2 ? 'true' : 'false']
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* The same events as a reader might be handed them: in any order, some of them
|
|
252
|
+
* twice (each repeat a copy, as a second relay answer would be).
|
|
253
|
+
*/
|
|
254
|
+
export function deliveryArb<T>(events: readonly T[]): fc.Arbitrary<T[]> {
|
|
255
|
+
const n = events.length
|
|
256
|
+
return fc
|
|
257
|
+
.tuple(fc.shuffledSubarray([...events], { minLength: n, maxLength: n }), fc.subarray([...events]))
|
|
258
|
+
.chain(([all, twice]) => {
|
|
259
|
+
const pool = [...all, ...twice.map((e) => JSON.parse(JSON.stringify(e)) as T)]
|
|
260
|
+
return fc.shuffledSubarray(pool, { minLength: pool.length, maxLength: pool.length })
|
|
261
|
+
})
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/** The starting number a pull request runs with: the same inputs on every run. */
|
|
265
|
+
export const FIXED_SEED = 20_261_120
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* The run's settings, from the environment: `FC_SEED` replays a run (CI sets a
|
|
269
|
+
* fresh one on each merge to `main` and prints it), `FC_RUNS` sets how many
|
|
270
|
+
* inputs each rule tries. Without them a run is the pull request's: the fixed
|
|
271
|
+
* seed and `defaultRuns`.
|
|
272
|
+
*/
|
|
273
|
+
export function runSettings(defaultRuns: number, env: Record<string, string | undefined> = processEnv()): { seed: number; numRuns: number } {
|
|
274
|
+
const seed = env.FC_SEED ? Number(env.FC_SEED) : FIXED_SEED
|
|
275
|
+
const runs = env.FC_RUNS ? Number(env.FC_RUNS) : defaultRuns
|
|
276
|
+
if (!Number.isSafeInteger(seed)) throw new Error(`FC_SEED is not a whole number: ${env.FC_SEED}`)
|
|
277
|
+
if (!Number.isSafeInteger(runs) || runs < 1) throw new Error(`FC_RUNS is not a positive whole number: ${env.FC_RUNS}`)
|
|
278
|
+
return { seed, numRuns: runs }
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
function processEnv(): Record<string, string | undefined> {
|
|
282
|
+
return (globalThis as { process?: { env?: Record<string, string | undefined> } }).process?.env ?? {}
|
|
283
|
+
}
|