sparta_worlds 0.6.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.txt +15 -0
- package/bin/worlds.js +53 -0
- package/dist/cli/argv.js +27 -0
- package/dist/cli/claims.js +250 -0
- package/dist/cli/commands.js +67 -0
- package/dist/cli/contract.js +142 -0
- package/dist/cli/demo.js +114 -0
- package/dist/cli/doctor.js +299 -0
- package/dist/cli/expect.js +197 -0
- package/dist/cli/home.js +18 -0
- package/dist/cli/import.js +530 -0
- package/dist/cli/index.js +1014 -0
- package/dist/cli/init.js +725 -0
- package/dist/cli/judge-command.js +184 -0
- package/dist/cli/judge.js +1495 -0
- package/dist/cli/load.js +8 -0
- package/dist/cli/packs.js +82 -0
- package/dist/cli/passk.js +1256 -0
- package/dist/cli/policy-starters.js +83 -0
- package/dist/cli/preload.js +45 -0
- package/dist/cli/report.js +579 -0
- package/dist/cli/rubric.js +727 -0
- package/dist/cli/run.js +266 -0
- package/dist/cli/scoreboard.js +432 -0
- package/dist/cli/selftest.js +157 -0
- package/dist/cli/stdio.js +25 -0
- package/dist/cli/tasks.js +1246 -0
- package/dist/cli/try.js +156 -0
- package/dist/cli/version.js +17 -0
- package/package.json +38 -0
- package/packs/cancellations.yaml +201 -0
- package/packs/credits.yaml +274 -0
- package/packs/invoices.yaml +206 -0
- package/packs/plan-changes.yaml +170 -0
- package/packs/refunds.yaml +437 -0
- package/preload/node-hooks.mjs +28 -0
- package/preload/node.mjs +19 -0
- package/preload/python/sitecustomize.py +88 -0
- package/preload/wrap.mjs +81 -0
- package/rubrics/acme-prod-library.json +1427 -0
- package/rubrics/acme-prod-shift.json +499 -0
- package/server/dist/admin/auth.js +145 -0
- package/server/dist/admin/routes.js +469 -0
- package/server/dist/admin/schemas.js +243 -0
- package/server/dist/app.js +112 -0
- package/server/dist/core/canonical.js +22 -0
- package/server/dist/core/db.js +294 -0
- package/server/dist/core/errors.js +136 -0
- package/server/dist/core/manager.js +337 -0
- package/server/dist/core/money.js +43 -0
- package/server/dist/core/nondeterministic.js +39 -0
- package/server/dist/core/paths.js +33 -0
- package/server/dist/core/prng.js +19 -0
- package/server/dist/core/protocol.js +1 -0
- package/server/dist/core/publicUrl.js +49 -0
- package/server/dist/core/seed.js +286 -0
- package/server/dist/core/seedExport.js +169 -0
- package/server/dist/core/seedLoader.js +156 -0
- package/server/dist/core/time.js +45 -0
- package/server/dist/core/world.js +361 -0
- package/server/dist/index.js +17 -0
- package/server/dist/main.js +42 -0
- package/server/dist/scenario/engine.js +172 -0
- package/server/dist/scenario/library.js +49 -0
- package/server/dist/twin/build.js +372 -0
- package/server/dist/twin/pagination.js +32 -0
- package/server/dist/twin/params.js +118 -0
- package/server/dist/twin/resources/charges.js +24 -0
- package/server/dist/twin/resources/customers.js +151 -0
- package/server/dist/twin/resources/events.js +26 -0
- package/server/dist/twin/resources/invoices.js +217 -0
- package/server/dist/twin/resources/payment_intents.js +146 -0
- package/server/dist/twin/resources/products.js +92 -0
- package/server/dist/twin/resources/refunds.js +103 -0
- package/server/dist/twin/resources/shared.js +113 -0
- package/server/dist/twin/resources/subscriptions.js +325 -0
- package/server/dist/twin/resources/tickets.js +128 -0
- package/server/dist/twin/router.js +279 -0
- package/server/dist/twin/unsupported.js +212 -0
- package/server/dist/webhooks/dispatcher.js +148 -0
- package/server/scenarios/auth-expiry.yaml +7 -0
- package/server/scenarios/intermittent-500s.yaml +9 -0
- package/server/scenarios/lock-timeouts.yaml +12 -0
- package/server/scenarios/rate-limit-storm.yaml +10 -0
- package/server/scenarios/slow-stripe.yaml +9 -0
- package/server/scenarios/stripe-storm-shift.yaml +15 -0
- package/server/scenarios/tickets-storm.yaml +10 -0
- package/server/scenarios/webhook-chaos.yaml +7 -0
- package/server/seeds/acme-prod-library.json +40470 -0
- package/server/seeds/acme-prod-shift.json +36544 -0
- package/server/seeds/acme-prod.json +35412 -0
- package/server/seeds/saas-billing-small.json +4792 -0
- package/server/seeds/saas-billing-smoke.json +160 -0
package/dist/cli/load.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { extname, resolve } from "node:path";
|
|
3
|
+
import { parse as parseYaml } from "yaml";
|
|
4
|
+
export function readDoc(file) {
|
|
5
|
+
const path = resolve(file);
|
|
6
|
+
const raw = readFileSync(path, "utf8");
|
|
7
|
+
return extname(path) === ".json" ? JSON.parse(raw) : parseYaml(raw);
|
|
8
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { parse as parseYaml } from "yaml";
|
|
5
|
+
import { parseTasks } from "./tasks.js";
|
|
6
|
+
export const AUTHORITIES = ["refunds", "credits", "cancellations", "plan-changes", "invoices"];
|
|
7
|
+
export const PACK_CAP = 15;
|
|
8
|
+
export const PACK_ALL = "all";
|
|
9
|
+
export function packsDir() {
|
|
10
|
+
const start = dirname(fileURLToPath(import.meta.url));
|
|
11
|
+
for (let dir = start;; dir = dirname(dir)) {
|
|
12
|
+
if (existsSync(join(dir, "package.json")) && existsSync(join(dir, "packs")))
|
|
13
|
+
return join(dir, "packs");
|
|
14
|
+
if (dirname(dir) === dir)
|
|
15
|
+
throw new Error(`no packs/ directory above ${start}`);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export function isAuthority(name) {
|
|
19
|
+
return AUTHORITIES.includes(name);
|
|
20
|
+
}
|
|
21
|
+
export function loadPack(authority, dir = packsDir()) {
|
|
22
|
+
const file = join(dir, `${authority}.yaml`);
|
|
23
|
+
if (!existsSync(file))
|
|
24
|
+
throw new Error(`no such pack: ${file}`);
|
|
25
|
+
return parseTasks(parseYaml(readFileSync(file, "utf8")), file);
|
|
26
|
+
}
|
|
27
|
+
const inboxNumber = (t) => {
|
|
28
|
+
const m = /^inbox-(\d+)$/.exec(t.id ?? "");
|
|
29
|
+
return m ? Number(m[1]) : Number.MAX_SAFE_INTEGER;
|
|
30
|
+
};
|
|
31
|
+
const byInbox = (x, y) => inboxNumber(x) - inboxNumber(y);
|
|
32
|
+
export function choosePacks(a) {
|
|
33
|
+
const out = [];
|
|
34
|
+
if (a.refundDays !== null)
|
|
35
|
+
out.push("refunds", "invoices");
|
|
36
|
+
if (a.credits !== null)
|
|
37
|
+
out.push("credits");
|
|
38
|
+
if (a.cancel !== "none")
|
|
39
|
+
out.push("cancellations");
|
|
40
|
+
if (a.planChanges)
|
|
41
|
+
out.push("plan-changes");
|
|
42
|
+
return out;
|
|
43
|
+
}
|
|
44
|
+
export function capTasks(tasks, cap) {
|
|
45
|
+
if (tasks.length <= cap)
|
|
46
|
+
return [...tasks];
|
|
47
|
+
const classes = new Set();
|
|
48
|
+
const first = [];
|
|
49
|
+
for (const t of tasks) {
|
|
50
|
+
const cls = t.trap_class ?? "unclassified";
|
|
51
|
+
if (classes.has(cls))
|
|
52
|
+
continue;
|
|
53
|
+
classes.add(cls);
|
|
54
|
+
first.push(t);
|
|
55
|
+
}
|
|
56
|
+
const rest = tasks.filter((t) => !first.includes(t));
|
|
57
|
+
return [...first, ...rest].slice(0, cap).sort(byInbox);
|
|
58
|
+
}
|
|
59
|
+
export function mergePacks(authorities, dir = packsDir(), opts = {}) {
|
|
60
|
+
const cap = opts.cap === undefined ? PACK_CAP : opts.cap;
|
|
61
|
+
const source = authorities.length === 0 ? ["refunds"] : authorities;
|
|
62
|
+
const loaded = new Map();
|
|
63
|
+
for (const a of source)
|
|
64
|
+
if (!loaded.has(a))
|
|
65
|
+
loaded.set(a, loadPack(a, dir));
|
|
66
|
+
const base = loaded.get(source[0]);
|
|
67
|
+
const seen = new Map();
|
|
68
|
+
for (const a of source) {
|
|
69
|
+
for (const t of loaded.get(a).tasks) {
|
|
70
|
+
const id = t.id ?? `${a}:${t.subject}`;
|
|
71
|
+
if (!seen.has(id))
|
|
72
|
+
seen.set(id, t);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
let all = [...seen.values()].sort(byInbox);
|
|
76
|
+
if (authorities.length === 0)
|
|
77
|
+
all = all.filter((t) => t.trap_class === "injection" || (t.trap_class === "identity" && t.expected === "escalate"));
|
|
78
|
+
return { ...base, tasks: cap === null ? all : capTasks(all, cap) };
|
|
79
|
+
}
|
|
80
|
+
export function libraryTaskCount(dir = packsDir()) {
|
|
81
|
+
return mergePacks(AUTHORITIES, dir, { cap: null }).tasks.length;
|
|
82
|
+
}
|