@mark1russell7/conventions 0.58.0 → 0.59.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.
@@ -0,0 +1,241 @@
1
+ import { parse } from "yaml";
2
+ import { escapeRegExp } from "@mark1russell7/text";
3
+ // src/permissions.ts
4
+ /**
5
+ * The permission gap of a call of a shared workflow. GitHub refuses a called workflow that asks for more permissions than
6
+ * its caller job grants: the run stops at its start (`startup_failure`). On 2026-11-26, the pins of a release workflow
7
+ * moved to a template commit whose `reusable-release-version.yml` asked for `actions: write`. Then each release run of that
8
+ * repository failed. The release train finds such a gap before it pushes the pins, and the rule `call-permissions` finds
9
+ * it in the checks of each repository. The two use the functions of this file (entry `@mark1russell7/conventions/permissions`).
10
+ *
11
+ * The rules of GitHub: the `permissions` of the caller job cap the called workflow. A caller job with no `permissions`
12
+ * gets the `permissions` of its workflow. `write` covers `read`. `read-all` and `write-all` set each scope. In the called
13
+ * workflow, a job with no `permissions` gets the `permissions` of its file. With none of the two, it asks for nothing more.
14
+ */
15
+ /** The scopes of the `GITHUB_TOKEN`. The report of a `write-all` ask names each of them. */
16
+ const PERMISSION_SCOPES = [
17
+ "actions",
18
+ "attestations",
19
+ "checks",
20
+ "contents",
21
+ "deployments",
22
+ "discussions",
23
+ "id-token",
24
+ "issues",
25
+ "models",
26
+ "packages",
27
+ "pages",
28
+ "pull-requests",
29
+ "repository-projects",
30
+ "security-events",
31
+ "statuses"
32
+ ];
33
+ /** The most levels of nested called workflows that the gate follows. GitHub lets a run have four levels. */
34
+ const CALL_DEPTH = 4;
35
+ const RANK = {
36
+ none: 0,
37
+ read: 1,
38
+ write: 2
39
+ };
40
+ function access(value) {
41
+ return value === "write" || value === "read" ? value : "none";
42
+ }
43
+ /**
44
+ * This function reads a `permissions` value of a workflow or of a job. It gives null when the value is absent: then the
45
+ * job inherits. `{}` gives no access. An unknown text gives no access.
46
+ */
47
+ function grantOf(value) {
48
+ if (value === void 0 || value === null) return null;
49
+ if (value === "write-all") return {
50
+ base: "write",
51
+ scopes: {}
52
+ };
53
+ if (value === "read-all") return {
54
+ base: "read",
55
+ scopes: {}
56
+ };
57
+ if (typeof value !== "object" || Array.isArray(value)) return {
58
+ base: "none",
59
+ scopes: {}
60
+ };
61
+ const scopes = {};
62
+ for (const [k, v] of Object.entries(value)) scopes[k] = access(v);
63
+ return {
64
+ base: "none",
65
+ scopes
66
+ };
67
+ }
68
+ function level(g, scope) {
69
+ return g.scopes[scope] ?? g.base;
70
+ }
71
+ /**
72
+ * This function gives each scope that `asked` asks for and that `granted` does not cover, in the order of the scope names.
73
+ * `write` covers `read`. An empty list is a pass.
74
+ */
75
+ function missingPermissions(granted, asked) {
76
+ const names = /* @__PURE__ */ new Set([...Object.keys(asked.scopes), ...Object.keys(granted.scopes)]);
77
+ if (asked.base !== "none") for (const s of PERMISSION_SCOPES) names.add(s);
78
+ const out = [];
79
+ for (const scope of [...names].sort()) {
80
+ const a = level(asked, scope);
81
+ const g = level(granted, scope);
82
+ if (RANK[a] > RANK[g]) out.push({
83
+ scope,
84
+ asked: a,
85
+ granted: g
86
+ });
87
+ }
88
+ return out;
89
+ }
90
+ function jobsOf(text) {
91
+ let doc;
92
+ try {
93
+ doc = parse(text);
94
+ } catch {
95
+ return null;
96
+ }
97
+ if (doc === null || typeof doc !== "object") return null;
98
+ const jobs = doc.jobs;
99
+ if (jobs === null || typeof jobs !== "object") return {
100
+ doc,
101
+ jobs: []
102
+ };
103
+ return {
104
+ doc,
105
+ jobs: Object.entries(jobs).map(([id, j]) => [id, j ?? {}])
106
+ };
107
+ }
108
+ /**
109
+ * This function gives each job of a workflow text that calls a shared workflow of the template at a commit. A ref of a
110
+ * composite action (`.github/actions/...`) has no permissions, so it is not in the list.
111
+ */
112
+ function templateCalls(text, owner, template = "template") {
113
+ const parsed = jobsOf(text);
114
+ if (!parsed) return [];
115
+ const re = new RegExp(`^${escapeRegExp(owner)}/${escapeRegExp(template)}/([^@\\s]+)@([0-9a-f]{40})$`);
116
+ const top = grantOf(parsed.doc.permissions);
117
+ const out = [];
118
+ for (const [job, j] of parsed.jobs) {
119
+ if (typeof j.uses !== "string") continue;
120
+ const m = re.exec(j.uses.trim());
121
+ if (!m?.[1] || !m[2] || m[1].startsWith(".github/actions/")) continue;
122
+ out.push({
123
+ job,
124
+ path: m[1],
125
+ sha: m[2],
126
+ grant: grantOf(j.permissions) ?? top
127
+ });
128
+ }
129
+ return out;
130
+ }
131
+ /** This function gives the key of a file of the template at a commit in a map of known files: `<path>@<sha>`. */
132
+ const fileKey = (file) => `${file.path}@${file.sha}`;
133
+ /**
134
+ * This function gives the gaps of calls over the files that `known` gives. A gap is a job of a called workflow, or of
135
+ * its nested calls, that asks for more than the cap of its call. A called file that is null in `known` is one gap
136
+ * with no missing permission (`unread`), so a gate holds. A called file that is not in `known` goes to `needs`. The walk
137
+ * reads no file, so a synchronous rule and an asynchronous reader use it the same way: read the needs, then walk again.
138
+ * Each walk goes one level of calls further, so the needs are empty after `CALL_DEPTH` reads at the most.
139
+ */
140
+ function walkGaps(calls, owner, known, template = "template") {
141
+ const out = [];
142
+ const needs = /* @__PURE__ */ new Map();
143
+ const nested = new RegExp(`^${escapeRegExp(owner)}/${escapeRegExp(template)}/(\\.github/workflows/[^@\\s]+)@([0-9a-f]{40})$`);
144
+ const walk = (call, cap, path, sha, chain, depth) => {
145
+ const key = fileKey({
146
+ path,
147
+ sha
148
+ });
149
+ if (!known.has(key)) {
150
+ needs.set(key, {
151
+ path,
152
+ sha
153
+ });
154
+ return;
155
+ }
156
+ const text = known.get(key) ?? null;
157
+ const parsed = text === null ? null : jobsOf(text);
158
+ if (!parsed) {
159
+ out.push({
160
+ job: call.job,
161
+ workflow: path,
162
+ sha,
163
+ calledJob: chain === "" ? null : chain,
164
+ missing: [],
165
+ unread: true
166
+ });
167
+ return;
168
+ }
169
+ const top = grantOf(parsed.doc.permissions);
170
+ for (const [id, j] of parsed.jobs) {
171
+ const name = chain === "" ? id : `${chain} > ${id}`;
172
+ const own = grantOf(j.permissions) ?? top;
173
+ if (own !== null) {
174
+ const missing = missingPermissions(cap, own);
175
+ if (missing.length > 0) out.push({
176
+ job: call.job,
177
+ workflow: call.path,
178
+ sha: call.sha,
179
+ calledJob: name,
180
+ missing,
181
+ unread: false
182
+ });
183
+ }
184
+ if (typeof j.uses !== "string" || depth >= CALL_DEPTH) continue;
185
+ const uses = j.uses.trim();
186
+ const local = uses.startsWith("./.github/workflows/") ? {
187
+ path: uses.slice(2),
188
+ sha
189
+ } : null;
190
+ const m = local ? null : nested.exec(uses);
191
+ const next = local ?? (m?.[1] && m[2] ? {
192
+ path: m[1],
193
+ sha: m[2]
194
+ } : null);
195
+ if (next) walk(call, own ?? cap, next.path, next.sha, name, depth + 1);
196
+ }
197
+ };
198
+ for (const call of calls) walk(call, call.grant, call.path, call.sha, "", 1);
199
+ return {
200
+ gaps: out,
201
+ needs: [...needs.values()]
202
+ };
203
+ }
204
+ /** This function gives the calls of a workflow text that a gap walk examines: each template call with a cap in the file. */
205
+ function checkedCalls(text, owner, template = "template") {
206
+ return templateCalls(text, owner, template).filter((call) => call.grant !== null);
207
+ }
208
+ /** This function walks the calls, and reads the needs of each walk with `read`, until the walk needs no file. */
209
+ async function readAndWalk(calls, owner, read, template) {
210
+ const known = /* @__PURE__ */ new Map();
211
+ for (;;) {
212
+ const { gaps, needs } = walkGaps(calls, owner, known, template);
213
+ if (needs.length === 0) return [...gaps];
214
+ const texts = await Promise.all(needs.map((file) => read(file.path, file.sha).catch(() => null)));
215
+ needs.forEach((file, i) => known.set(fileKey(file), texts[i] ?? null));
216
+ }
217
+ }
218
+ /**
219
+ * This function gives the gaps of one call: each job of the called workflow (and of its nested calls) whose permissions
220
+ * the cap of the call does not cover. A called file that `read` cannot give is one gap with no called job, so the gate holds.
221
+ */
222
+ async function callGaps(call, owner, read, template = "template") {
223
+ return readAndWalk([call], owner, read, template);
224
+ }
225
+ /** This function gives the gaps of each template call of a workflow text (refer to `checkedCalls`). */
226
+ async function workflowGaps(text, owner, read, template = "template") {
227
+ return readAndWalk(checkedCalls(text, owner, template), owner, read, template);
228
+ }
229
+ /** This function gives one line of a gap for the report: the caller job, the called workflow and each missing permission. */
230
+ function gapLine(path, g) {
231
+ const at = `\`${g.workflow}\` at \`${g.sha.slice(0, 7)}\``;
232
+ if (g.unread) {
233
+ const through = g.calledJob === null ? "" : ` (through its job \`${g.calledJob}\`)`;
234
+ return `\`${path}\` job \`${g.job}\` calls ${at}${through}, but its file cannot be read, so the permission check cannot examine it.`;
235
+ }
236
+ const list = g.missing.map((m) => `\`${m.scope}: ${m.asked}\` (the caller grants \`${m.granted}\`)`).join(", ");
237
+ return `\`${path}\` job \`${g.job}\` calls ${at}. Its job \`${g.calledJob}\` asks for ${list}. GitHub refuses such a run at its start. Add the permissions to the caller job, or remove them from the template.`;
238
+ }
239
+ export { PERMISSION_SCOPES, callGaps, checkedCalls, fileKey, gapLine, grantOf, missingPermissions, templateCalls, walkGaps, workflowGaps };
240
+
241
+ //# sourceMappingURL=permissions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"permissions.js","names":["parseYaml","escapeRe"],"sources":["../src/permissions.ts"],"sourcesContent":["/**\n * The permission gap of a call of a shared workflow. GitHub refuses a called workflow that asks for more permissions than\n * its caller job grants: the run stops at its start (`startup_failure`). On 2026-11-26, the pins of a release workflow\n * moved to a template commit whose `reusable-release-version.yml` asked for `actions: write`. Then each release run of that\n * repository failed. The release train finds such a gap before it pushes the pins, and the rule `call-permissions` finds\n * it in the checks of each repository. The two use the functions of this file (entry `@mark1russell7/conventions/permissions`).\n *\n * The rules of GitHub: the `permissions` of the caller job cap the called workflow. A caller job with no `permissions`\n * gets the `permissions` of its workflow. `write` covers `read`. `read-all` and `write-all` set each scope. In the called\n * workflow, a job with no `permissions` gets the `permissions` of its file. With none of the two, it asks for nothing more.\n */\nimport { parse as parseYaml } from \"yaml\";\nimport { escapeRegExp as escapeRe } from \"@mark1russell7/text\";\n\n/** The access of one permission scope. */\nexport type Access = \"none\" | \"read\" | \"write\";\n\n/** The permissions of a job: the access of each named scope, and the access of each other scope. */\nexport interface Grant {\n /** The access of each scope that the block does not name. `read-all` gives `read`, `write-all` gives `write`, a map gives `none`. */\n readonly base: Access;\n readonly scopes: Readonly<Record<string, Access>>;\n}\n\n/** One scope that a called job asks for and that its caller does not grant. */\nexport interface MissingPermission {\n readonly scope: string;\n readonly asked: Access;\n readonly granted: Access;\n}\n\n/** One gap of the permission gate: a caller job, the called workflow, and the scopes of one called job that its caller does not grant. */\nexport interface PermissionGap {\n /** The job of the caller workflow. */\n readonly job: string;\n /** The path of the called workflow in the template. */\n readonly workflow: string;\n /** The commit of the called workflow. */\n readonly sha: string;\n /** The job of the called workflow that asks, with the jobs of the nested calls before it (`a > b`). Null for the file of the caller job. */\n readonly calledJob: string | null;\n readonly missing: readonly MissingPermission[];\n /** This value is true when the train cannot read the called file (`workflow` at `sha`). Then the gate cannot check it, so it holds. */\n readonly unread: boolean;\n}\n\n/** This function reads a file of the template at a commit, or gives null. */\nexport type ReadAt = (path: string, sha: string) => Promise<string | null>;\n\n/** The scopes of the `GITHUB_TOKEN`. The report of a `write-all` ask names each of them. */\nexport const PERMISSION_SCOPES: readonly string[] = [\n \"actions\",\n \"attestations\",\n \"checks\",\n \"contents\",\n \"deployments\",\n \"discussions\",\n \"id-token\",\n \"issues\",\n \"models\",\n \"packages\",\n \"pages\",\n \"pull-requests\",\n \"repository-projects\",\n \"security-events\",\n \"statuses\",\n];\n\n/** The most levels of nested called workflows that the gate follows. GitHub lets a run have four levels. */\nconst CALL_DEPTH = 4;\n\nconst RANK: Readonly<Record<Access, number>> = { none: 0, read: 1, write: 2 };\n\nfunction access(value: unknown): Access {\n return value === \"write\" || value === \"read\" ? value : \"none\";\n}\n\n/**\n * This function reads a `permissions` value of a workflow or of a job. It gives null when the value is absent: then the\n * job inherits. `{}` gives no access. An unknown text gives no access.\n */\nexport function grantOf(value: unknown): Grant | null {\n if (value === undefined || value === null) return null;\n if (value === \"write-all\") return { base: \"write\", scopes: {} };\n if (value === \"read-all\") return { base: \"read\", scopes: {} };\n if (typeof value !== \"object\" || Array.isArray(value)) return { base: \"none\", scopes: {} };\n const scopes: Record<string, Access> = {};\n for (const [k, v] of Object.entries(value as Record<string, unknown>)) scopes[k] = access(v);\n return { base: \"none\", scopes };\n}\n\nfunction level(g: Grant, scope: string): Access {\n return g.scopes[scope] ?? g.base;\n}\n\n/**\n * This function gives each scope that `asked` asks for and that `granted` does not cover, in the order of the scope names.\n * `write` covers `read`. An empty list is a pass.\n */\nexport function missingPermissions(granted: Grant, asked: Grant): MissingPermission[] {\n const names = new Set([...Object.keys(asked.scopes), ...Object.keys(granted.scopes)]);\n if (asked.base !== \"none\") for (const s of PERMISSION_SCOPES) names.add(s);\n const out: MissingPermission[] = [];\n for (const scope of [...names].sort()) {\n const a = level(asked, scope);\n const g = level(granted, scope);\n if (RANK[a] > RANK[g]) out.push({ scope, asked: a, granted: g });\n }\n return out;\n}\n\ninterface WorkflowDoc {\n permissions?: unknown;\n jobs?: unknown;\n}\n\ninterface JobDoc {\n permissions?: unknown;\n uses?: unknown;\n}\n\nfunction jobsOf(text: string): { doc: WorkflowDoc; jobs: [string, JobDoc][] } | null {\n let doc: unknown;\n try {\n doc = parseYaml(text);\n } catch {\n return null;\n }\n if (doc === null || typeof doc !== \"object\") return null;\n const jobs = (doc as WorkflowDoc).jobs;\n if (jobs === null || typeof jobs !== \"object\") return { doc: doc as WorkflowDoc, jobs: [] };\n return { doc: doc as WorkflowDoc, jobs: Object.entries(jobs as Record<string, unknown>).map(([id, j]) => [id, (j ?? {}) as JobDoc]) };\n}\n\n/** One job of a caller workflow that calls a shared workflow of the template. */\nexport interface TemplateCall {\n readonly job: string;\n readonly path: string;\n readonly sha: string;\n /** The cap of the call: the `permissions` of the job, else of the workflow. Null when the file sets none: the cap is the default of the repository. */\n readonly grant: Grant | null;\n}\n\n/**\n * This function gives each job of a workflow text that calls a shared workflow of the template at a commit. A ref of a\n * composite action (`.github/actions/...`) has no permissions, so it is not in the list.\n */\nexport function templateCalls(text: string, owner: string, template = \"template\"): TemplateCall[] {\n const parsed = jobsOf(text);\n if (!parsed) return [];\n const re = new RegExp(`^${escapeRe(owner)}/${escapeRe(template)}/([^@\\\\s]+)@([0-9a-f]{40})$`);\n const top = grantOf(parsed.doc.permissions);\n const out: TemplateCall[] = [];\n for (const [job, j] of parsed.jobs) {\n if (typeof j.uses !== \"string\") continue;\n const m = re.exec(j.uses.trim());\n if (!m?.[1] || !m[2] || m[1].startsWith(\".github/actions/\")) continue;\n out.push({ job, path: m[1], sha: m[2], grant: grantOf(j.permissions) ?? top });\n }\n return out;\n}\n\n/** A file of the template at a commit. */\nexport interface TemplateFile {\n readonly path: string;\n readonly sha: string;\n}\n\n/** This function gives the key of a file of the template at a commit in a map of known files: `<path>@<sha>`. */\nexport const fileKey = (file: TemplateFile): string => `${file.path}@${file.sha}`;\n\n/**\n * The files of the template that a walk knows: the text of each key of `fileKey`, or null when the file cannot be read.\n * A key that is not in the map is a file that the walk needs.\n */\nexport type KnownFiles = ReadonlyMap<string, string | null>;\n\n/** The result of a walk over the known files: the gaps, and the files that the walk needs and does not know. */\nexport interface GapWalk {\n readonly gaps: readonly PermissionGap[];\n /** The files to read before the next walk. When it is empty, `gaps` is the full result. */\n readonly needs: readonly TemplateFile[];\n}\n\n/**\n * This function gives the gaps of calls over the files that `known` gives. A gap is a job of a called workflow, or of\n * its nested calls, that asks for more than the cap of its call. A called file that is null in `known` is one gap\n * with no missing permission (`unread`), so a gate holds. A called file that is not in `known` goes to `needs`. The walk\n * reads no file, so a synchronous rule and an asynchronous reader use it the same way: read the needs, then walk again.\n * Each walk goes one level of calls further, so the needs are empty after `CALL_DEPTH` reads at the most.\n */\nexport function walkGaps(calls: readonly (TemplateCall & { readonly grant: Grant })[], owner: string, known: KnownFiles, template = \"template\"): GapWalk {\n const out: PermissionGap[] = [];\n const needs = new Map<string, TemplateFile>();\n const nested = new RegExp(`^${escapeRe(owner)}/${escapeRe(template)}/(\\\\.github/workflows/[^@\\\\s]+)@([0-9a-f]{40})$`);\n const walk = (call: TemplateCall, cap: Grant, path: string, sha: string, chain: string, depth: number): void => {\n const key = fileKey({ path, sha });\n if (!known.has(key)) {\n needs.set(key, { path, sha });\n return;\n }\n const text = known.get(key) ?? null;\n const parsed = text === null ? null : jobsOf(text);\n if (!parsed) {\n out.push({ job: call.job, workflow: path, sha, calledJob: chain === \"\" ? null : chain, missing: [], unread: true });\n return;\n }\n const top = grantOf(parsed.doc.permissions);\n for (const [id, j] of parsed.jobs) {\n const name = chain === \"\" ? id : `${chain} > ${id}`;\n const own = grantOf(j.permissions) ?? top;\n if (own !== null) {\n const missing = missingPermissions(cap, own);\n if (missing.length > 0) out.push({ job: call.job, workflow: call.path, sha: call.sha, calledJob: name, missing, unread: false });\n }\n if (typeof j.uses !== \"string\" || depth >= CALL_DEPTH) continue;\n const uses = j.uses.trim();\n // A local ref of a called workflow names a file of the same repository and commit.\n const local = uses.startsWith(\"./.github/workflows/\") ? { path: uses.slice(2), sha } : null;\n const m = local ? null : nested.exec(uses);\n const next = local ?? (m?.[1] && m[2] ? { path: m[1], sha: m[2] } : null);\n // The own permissions of the job cap its nested call. A job with none passes the cap of its caller.\n if (next) walk(call, own ?? cap, next.path, next.sha, name, depth + 1);\n }\n };\n for (const call of calls) walk(call, call.grant, call.path, call.sha, \"\", 1);\n return { gaps: out, needs: [...needs.values()] };\n}\n\n/** This function gives the calls of a workflow text that a gap walk examines: each template call with a cap in the file. */\nexport function checkedCalls(text: string, owner: string, template = \"template\"): (TemplateCall & { readonly grant: Grant })[] {\n // A call whose cap is the default of the repository (no `permissions` in the job or in the workflow) is not examined,\n // because the default is not known.\n return templateCalls(text, owner, template).filter((call): call is TemplateCall & { readonly grant: Grant } => call.grant !== null);\n}\n\n/** This function walks the calls, and reads the needs of each walk with `read`, until the walk needs no file. */\nasync function readAndWalk(calls: readonly (TemplateCall & { readonly grant: Grant })[], owner: string, read: ReadAt, template: string): Promise<PermissionGap[]> {\n const known = new Map<string, string | null>();\n for (;;) {\n const { gaps, needs } = walkGaps(calls, owner, known, template);\n if (needs.length === 0) return [...gaps];\n const texts = await Promise.all(needs.map((file) => read(file.path, file.sha).catch(() => null)));\n needs.forEach((file, i) => known.set(fileKey(file), texts[i] ?? null));\n }\n}\n\n/**\n * This function gives the gaps of one call: each job of the called workflow (and of its nested calls) whose permissions\n * the cap of the call does not cover. A called file that `read` cannot give is one gap with no called job, so the gate holds.\n */\nexport async function callGaps(call: TemplateCall & { readonly grant: Grant }, owner: string, read: ReadAt, template = \"template\"): Promise<PermissionGap[]> {\n return readAndWalk([call], owner, read, template);\n}\n\n/** This function gives the gaps of each template call of a workflow text (refer to `checkedCalls`). */\nexport async function workflowGaps(text: string, owner: string, read: ReadAt, template = \"template\"): Promise<PermissionGap[]> {\n return readAndWalk(checkedCalls(text, owner, template), owner, read, template);\n}\n\n/** This function gives one line of a gap for the report: the caller job, the called workflow and each missing permission. */\nexport function gapLine(path: string, g: PermissionGap): string {\n const at = `\\`${g.workflow}\\` at \\`${g.sha.slice(0, 7)}\\``;\n if (g.unread) {\n const through = g.calledJob === null ? \"\" : ` (through its job \\`${g.calledJob}\\`)`;\n return `\\`${path}\\` job \\`${g.job}\\` calls ${at}${through}, but its file cannot be read, so the permission check cannot examine it.`;\n }\n const list = g.missing.map((m) => `\\`${m.scope}: ${m.asked}\\` (the caller grants \\`${m.granted}\\`)`).join(\", \");\n return `\\`${path}\\` job \\`${g.job}\\` calls ${at}. Its job \\`${g.calledJob}\\` asks for ${list}. GitHub refuses such a run at its start. Add the permissions to the caller job, or remove them from the template.`;\n}\n"],"mappings":";;;;;;;;;;;;;;;AAkDA,MAAa,oBAAuC;CAClD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;AAGA,MAAM,aAAa;AAEnB,MAAM,OAAyC;CAAE,MAAM;CAAG,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