~james/core

core/web/src/fixtures/githubImportWorstCase.ts -rw-r--r-- 6.5 KiB
452f17b7 — james chore(import): snapshot james.dad.town/core at f70c71c7696a 15 hours ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import type { MigrationTask } from "#lib/api/migrator.ts";
import type { GitHubRepo } from "#lib/github.ts";

export type GitHubImportDatasetName = "demo" | "worst" | "empty" | "one" | "huge";

export interface GitHubImportDataset {
	repos: GitHubRepo[];
	knots: string[];
	tasks: MigrationTask[];
}

const owner = "aleksandra-wisniewska-kowalczyk";

const repo = (
	id: number,
	name: string,
	fields: Partial<Omit<GitHubRepo, "id" | "name">> = {}
): GitHubRepo => ({
	id,
	name,
	fullName: `${owner}/${name}`,
	description: null,
	cloneUrl: `https://github.com/${owner}/${name}.git`,
	htmlUrl: `https://github.com/${owner}/${name}`,
	defaultBranch: "main",
	...fields
});

type Job = MigrationTask["jobs"][number];
type JobFields = Partial<Job>;

const job = (id: string, name: string, status: string, fields: JobFields = {}): Job => ({
	id,
	name,
	knotDid: "did:web:knot.northwind-industries-holdings.example.com",
	sourceUrl: `https://github.com/${owner}/${name}.git`,
	private: false,
	status,
	attempts: 1,
	...fields
});

const task = (id: string, jobs: MigrationTask["jobs"]): MigrationTask => ({
	id,
	ownerDid: "did:plc:alice",
	createdAt: "2026-10-27T09:14:00Z",
	jobs
});

const longestName =
	"NorthwindIndustriesHoldings.Platform.Infrastructure.Terraform.Modules.AWS.eu-central-1.production.v2".slice(
		0,
		100
	);

const proxyErrorPage = `knot createRepo returned HTTP 502: <!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js ie6 oldie" lang="en-US"> <![endif]-->
<html class="no-js" lang="en-US"><head><title>knot.northwind-industries-holdings.example.com | 502: Bad gateway</title><meta charset="UTF-8" /><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><meta http-equiv="X-UA-Compatible" content="IE=Edge" /><meta name="robots" content="noindex, nofollow" /><meta name="viewport" content="width=device-width,initial-scale=1" /><link rel="stylesheet" id="cf_styles-css" href="/cdn-cgi/styles/main.css" /></head><body><div id="cf-wrapper"><div id="cf-error-details" class="p-0"><header class="mx-auto pt-10 lg:pt-6 lg:px-8 w-240 lg:w-full mb-8"><h1 class="inline-block sm:block sm:mb-2 font-light text-60 lg:text-4xl text-black-dark leading-tight mr-2"><span class="inline-block">Bad gateway</span><span class="code-label">Error code 502</span></h1><div>Visit <a href="https://www.example.com/5xx-error-landing?utm_source=errorcode_502&amp;utm_campaign=knot.northwind-industries-holdings.example.com" target="_blank" rel="noopener noreferrer">example.com</a> for more information.</div><div class="mt-3">2026-10-27 09:14:07 UTC</div></header></div></div></body></html>`;

const worstRepos: GitHubRepo[] = [
	repo(1, longestName, {
		description:
			"Shared Terraform modules for every production account in eu-central-1, including VPC peering, Transit Gateway attachments, IAM permission boundaries, KMS key policies, and the Datadog forwarder. Owned by Platform Infrastructure; ask in #platform-infra before changing anything under modules/networking/.",
		language: "HCL",
		stars: 1284,
		private: true
	}),
	repo(2, "a", { description: null, language: null, stars: 0 }),
	repo(3, "dotfiles", {
		description: "🦊 My config — 設定ファイル & scripts for zsh, nvim, and <tmux>",
		language: "Vim Script",
		stars: 1,
		private: true
	}),
	repo(4, "Q3-board-deck-FINAL-revised-v12-approved-by-legal", {
		description: "Fix &amp; escaping in **bold** headings",
		language: "Common Workflow Language",
		stars: 128_400
	}),
	repo(5, "benachrichtigungseinstellungen", {
		description: "Paramètres de confidentialité et de sécurité pour les notifications",
		language: "Jupyter Notebook",
		stars: 999_999
	}),
	...Array.from({ length: 18 }, (_, i) =>
		repo(6 + i, `service-${String(i + 1).padStart(2, "0")}`, {
			description: i % 3 === 0 ? null : `Internal service ${i + 1}`,
			language: i % 2 === 0 ? "Go" : "TypeScript",
			stars: i * 7
		})
	)
];

const worstTasks: MigrationTask[] = [
	task("task-worst", [
		job("job-proxy", longestName, "failed", { error: proxyErrorPage, private: true }),
		job("job-a", "a", "queued"),
		job("job-dotfiles", "dotfiles", "completed", {
			repoDid: "did:plc:7f3k2m9xq4w8z1v5n6b0c2d4"
		}),
		job("job-deck", "Q3-board-deck-FINAL-revised-v12-approved-by-legal", "failed", {
			error: `a repository named "Q3-board-deck-FINAL-revised-v12-approved-by-legal" already exists on did:web:knot.northwind-industries-holdings.example.com and was not created from https://github.com/${owner}/Q3-board-deck-FINAL-revised-v12-approved-by-legal.git`
		}),
		job("job-benach", "benachrichtigungseinstellungen", "importing"),
		job("job-404", "service-01", "failed", { error: "knot createRepo returned HTTP 404: " }),
		job("job-grant", "service-02", "authorization_required", {
			error: "ScopeMissingError: Missing required scope rpc:org.tangled.repo.createRepo?aud=*"
		}),
		job("job-cloning", "service-03", "cloning"),
		job("job-unknown", "service-04", "paused"),
		job("job-silent", "service-05", "failed")
	])
];

const demo: GitHubImportDataset = {
	repos: [
		repo(1, "alpha", { description: "first" }),
		repo(2, "beta", { description: "second" }),
		repo(3, "gamma", { description: "third" })
	],
	knots: ["knot.example.test"],
	tasks: [task("task-earlier", [job("job-earlier", "delta", "completed")])]
};

const statuses = ["completed", "failed", "queued", "cloning", "importing", "completed"];

export const githubImportDatasets: Record<GitHubImportDatasetName, GitHubImportDataset> = {
	demo,
	worst: {
		repos: worstRepos,
		knots: [
			"knot.northwind-industries-holdings.example.com",
			"k.example.test",
			"eu-central-1.knots.sub.department.region.example.co.uk"
		],
		tasks: worstTasks
	},
	empty: { repos: [], knots: [], tasks: [] },
	one: {
		repos: [repo(1, "dotfiles", { description: "My config", language: "Shell", stars: 1 })],
		knots: ["knot.example.test"],
		tasks: [task("task-one", [job("job-one", "dotfiles", "completed")])]
	},
	huge: {
		repos: Array.from({ length: 1284 }, (_, i) =>
			repo(i + 1, `repository-${String(i + 1).padStart(4, "0")}`, {
				description: `Repository number ${i + 1}`,
				language: i % 2 === 0 ? "Rust" : "Python",
				stars: i * 13
			})
		),
		knots: ["knot.example.test"],
		tasks: Array.from({ length: 20 }, (_, t) =>
			task(
				`task-${t}`,
				Array.from({ length: 50 }, (_, j) => {
					const n = t * 50 + j + 1;
					const status = statuses[n % statuses.length];
					return job(
						`job-${n}`,
						`repository-${String(n).padStart(4, "0")}`,
						status,
						status === "failed" ? { error: "knot createRepo returned HTTP 404: " } : {}
					);
				})
			)
		)
	}
};