@volter/twin-github 0.1.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/LICENSE +202 -0
- package/README.md +80 -0
- package/client/github-mirror.css +958 -0
- package/client/github-mirror.tsx +1513 -0
- package/package.json +73 -0
- package/src/cli.ts +40 -0
- package/src/github-capabilities.ts +2144 -0
- package/src/github-conformance.ts +94 -0
- package/src/github-connector.ts +644 -0
- package/src/github-events.ts +95 -0
- package/src/github-graphql.ts +187 -0
- package/src/github-mirror-ui.ts +416 -0
- package/src/github-server.ts +35 -0
- package/src/github-twin.ts +6568 -0
- package/src/github-ui-conformance.ts +112 -0
- package/src/github-ui-structure.ts +256 -0
- package/src/index.ts +23 -0
- package/test-fixtures/github-a11y-reference.pr-list.json +1447 -0
- package/test-fixtures/github-comment-schema.json +702 -0
- package/test-fixtures/github-known-deviations.json +95 -0
- package/test-fixtures/github-openapi-operations.json +110 -0
- package/test-fixtures/github-pull-schema.json +3601 -0
- package/test-fixtures/github-review-schema.json +236 -0
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// GitHub twin conformance (scorecard R2) — spec-conformance against GitHub's
|
|
2
|
+
// PUBLISHED pull-request schema, not a hand-authored field-name list. Offline, no
|
|
3
|
+
// token: for every PR the twin serves, validate the REST response against the real
|
|
4
|
+
// schema (types, required, enums, fabricated extras) vendored from GitHub's OpenAPI
|
|
5
|
+
// (test-fixtures/github-pull-schema.json). Twin-namespaced extras (keys starting
|
|
6
|
+
// `_`) are skipped. Fields the evidence twin deliberately does not model are DECLARED
|
|
7
|
+
// in github-known-deviations.json with reasons — a missing-required field that is
|
|
8
|
+
// NOT declared fails CI. The companion coverage report says what we emit vs what the
|
|
9
|
+
// vendor declares. Standing gate: wrong types, undeclared omissions, fabricated
|
|
10
|
+
// surface, or enum violations all fail.
|
|
11
|
+
import { specConformance } from '@volter/twin-tooling';
|
|
12
|
+
import { githubState, toGithubComment, toGithubRest, toGithubReview } from './github-twin.ts';
|
|
13
|
+
|
|
14
|
+
type JsonSchema = specConformance.JsonSchema;
|
|
15
|
+
type KnownDeviation = specConformance.KnownDeviation;
|
|
16
|
+
type SpecViolation = specConformance.SpecViolation;
|
|
17
|
+
|
|
18
|
+
export type GithubViolation = SpecViolation & { prId: string };
|
|
19
|
+
export type GithubConformanceReport = {
|
|
20
|
+
ok: boolean;
|
|
21
|
+
prsChecked: number;
|
|
22
|
+
fieldsChecked: number;
|
|
23
|
+
violations: GithubViolation[];
|
|
24
|
+
knownIgnored: number;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const isTwinExtra = (f: string): boolean => f.startsWith('_');
|
|
28
|
+
const fixturePath = (name: string): string => new URL(`../test-fixtures/${name}`, import.meta.url).pathname;
|
|
29
|
+
|
|
30
|
+
/** Load the vendored full GitHub pull-request JSON Schema (dereferenced OpenAPI). */
|
|
31
|
+
export async function loadGithubPrSchema(): Promise<JsonSchema> {
|
|
32
|
+
return JSON.parse(await Bun.file(fixturePath('github-pull-schema.json')).text()) as JsonSchema;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Load the vendored GitHub pull-request-review JSON Schema. */
|
|
36
|
+
export async function loadGithubReviewSchema(): Promise<JsonSchema> {
|
|
37
|
+
return JSON.parse(await Bun.file(fixturePath('github-review-schema.json')).text()) as JsonSchema;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Load the vendored GitHub issue-comment JSON Schema. */
|
|
41
|
+
export async function loadGithubCommentSchema(): Promise<JsonSchema> {
|
|
42
|
+
return JSON.parse(await Bun.file(fixturePath('github-comment-schema.json')).text()) as JsonSchema;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Load the declared evidence-twin scope (fields deliberately not modeled, + reasons). */
|
|
46
|
+
export async function loadGithubKnownDeviations(): Promise<KnownDeviation[]> {
|
|
47
|
+
const doc = JSON.parse(await Bun.file(fixturePath('github-known-deviations.json')).text()) as { deviations: KnownDeviation[] };
|
|
48
|
+
return doc.deviations;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Validate every PR the twin serves against the real GitHub PR schema. A wrong
|
|
53
|
+
* type, an undeclared missing-required field, a fabricated field, or an enum
|
|
54
|
+
* violation fails the report.
|
|
55
|
+
*/
|
|
56
|
+
export function checkGithubConformance(schema: JsonSchema, opts: { root?: string; known?: KnownDeviation[] } = {}): GithubConformanceReport {
|
|
57
|
+
const state = githubState(opts.root);
|
|
58
|
+
const violations: GithubViolation[] = [];
|
|
59
|
+
let fieldsChecked = 0;
|
|
60
|
+
let knownIgnored = 0;
|
|
61
|
+
for (const pr of state.prs) {
|
|
62
|
+
const rest = toGithubRest(pr);
|
|
63
|
+
const rep = specConformance.checkSpecConformance(rest, schema, { exemptKey: isTwinExtra, known: opts.known ?? [] });
|
|
64
|
+
fieldsChecked += rep.fieldsChecked;
|
|
65
|
+
knownIgnored += rep.knownIgnored;
|
|
66
|
+
for (const v of rep.violations) violations.push({ ...v, prId: pr.id });
|
|
67
|
+
}
|
|
68
|
+
return { ok: violations.length === 0, prsChecked: state.prs.length, fieldsChecked, violations, knownIgnored };
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export type GithubCoverageReport = specConformance.SpecCoverageReport;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Top-level coverage: of the fields the GitHub PR schema declares, which does the
|
|
75
|
+
* twin emit? The "what we emulate / what we're missing" report — computed from the
|
|
76
|
+
* spec, not probed live. Uses a representative content-bearing PR sample.
|
|
77
|
+
*/
|
|
78
|
+
export function githubCoverage(schema: JsonSchema): GithubCoverageReport {
|
|
79
|
+
const sample = toGithubRest({
|
|
80
|
+
id: 'o/r#1', number: 1, repository: 'o/r', base_ref: 'main', head_sha: 'abc123',
|
|
81
|
+
changed_files: 3, commits: 2, review_count: 0, comment_count: 0, title: 'Sample', state: 'open',
|
|
82
|
+
});
|
|
83
|
+
return specConformance.specCoverage(schema, sample, { exemptKey: isTwinExtra });
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** Coverage of the pull-request-review object the twin emits on review submission. */
|
|
87
|
+
export function githubReviewCoverage(schema: JsonSchema): GithubCoverageReport {
|
|
88
|
+
return specConformance.specCoverage(schema, toGithubReview({ id: 1, repository: 'o/r', number: 1, state: 'APPROVED', body: 'lgtm' }), { exemptKey: isTwinExtra });
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Coverage of the issue-comment object the twin emits on comment creation. */
|
|
92
|
+
export function githubCommentCoverage(schema: JsonSchema): GithubCoverageReport {
|
|
93
|
+
return specConformance.specCoverage(schema, toGithubComment({ id: 1, repository: 'o/r', number: 1, body: 'hi', at: '2026-01-01T00:00:00Z' }), { exemptKey: isTwinExtra });
|
|
94
|
+
}
|