@specific.dev/spectest 0.39.0 → 0.43.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.
Files changed (105) hide show
  1. package/dist/browser.d.ts +21 -8
  2. package/dist/browser.js +78 -36
  3. package/dist/components/supabase.d.ts +87 -27
  4. package/dist/components/supabase.js +352 -69
  5. package/dist/daemon.d.ts +38 -0
  6. package/dist/daemon.js +464 -987
  7. package/dist/harness/build-context.d.ts +82 -0
  8. package/dist/harness/build-context.js +113 -0
  9. package/dist/harness/buildkit-progress.d.ts +37 -0
  10. package/dist/harness/buildkit-progress.js +66 -0
  11. package/dist/harness/container-run.d.ts +89 -0
  12. package/dist/harness/container-run.js +118 -0
  13. package/dist/harness/file-mounts.d.ts +91 -0
  14. package/dist/harness/file-mounts.js +119 -0
  15. package/dist/harness/hostmatch.d.ts +65 -0
  16. package/dist/harness/hostmatch.js +108 -0
  17. package/dist/harness/http-proxy.d.ts +62 -0
  18. package/dist/harness/http-proxy.js +104 -0
  19. package/dist/harness/ingress-table.d.ts +148 -0
  20. package/dist/harness/ingress-table.js +129 -0
  21. package/dist/harness/log-delta.d.ts +54 -0
  22. package/dist/harness/log-delta.js +83 -0
  23. package/dist/harness/main.d.ts +47 -0
  24. package/dist/harness/main.js +164 -0
  25. package/dist/harness/methods.d.ts +54 -0
  26. package/dist/harness/methods.js +65 -0
  27. package/dist/harness/names-registry.d.ts +63 -0
  28. package/dist/harness/names-registry.js +90 -0
  29. package/dist/harness/protocol.d.ts +88 -0
  30. package/dist/harness/protocol.js +96 -0
  31. package/dist/harness/ready-poll.d.ts +47 -0
  32. package/dist/harness/ready-poll.js +67 -0
  33. package/dist/harness/service-graph.d.ts +29 -0
  34. package/dist/harness/service-graph.js +92 -0
  35. package/dist/harness/volume-paths.d.ts +70 -0
  36. package/dist/harness/volume-paths.js +81 -0
  37. package/dist/index.d.ts +58 -16
  38. package/dist/ingress.d.ts +1 -1
  39. package/dist/mobile.d.ts +9 -5
  40. package/dist/mobile.js +7 -6
  41. package/dist/recorder.d.ts +10 -0
  42. package/dist/resolver.js +5 -8
  43. package/dist/vendor/rrweb-plugin-console-record.umd.js +521 -0
  44. package/dist/vendor/rrweb-record.min.js +5061 -0
  45. package/package.json +7 -1
  46. package/src/aws-sigv4.ts +218 -0
  47. package/src/browser.ts +2095 -0
  48. package/src/components/aws.ts +554 -0
  49. package/src/components/email.ts +398 -0
  50. package/src/components/expo.ts +167 -0
  51. package/src/components/index.ts +81 -0
  52. package/src/components/k3s.ts +2061 -0
  53. package/src/components/postgres.ts +132 -0
  54. package/src/components/replayFake.ts +1015 -0
  55. package/src/components/s3.ts +132 -0
  56. package/src/components/supabase.ts +1699 -0
  57. package/src/daemon.ts +5537 -0
  58. package/src/harness/build-context.test.ts +0 -0
  59. package/src/harness/build-context.ts +146 -0
  60. package/src/harness/buildkit-progress.test.ts +98 -0
  61. package/src/harness/buildkit-progress.ts +74 -0
  62. package/src/harness/container-run.test.ts +209 -0
  63. package/src/harness/container-run.ts +158 -0
  64. package/src/harness/file-mounts.test.ts +185 -0
  65. package/src/harness/file-mounts.ts +145 -0
  66. package/src/harness/hostmatch.test.ts +148 -0
  67. package/src/harness/hostmatch.ts +109 -0
  68. package/src/harness/http-proxy.test.ts +156 -0
  69. package/src/harness/http-proxy.ts +119 -0
  70. package/src/harness/ingress-rebind.test.ts +125 -0
  71. package/src/harness/ingress-table.test.ts +172 -0
  72. package/src/harness/ingress-table.ts +186 -0
  73. package/src/harness/log-delta.test.ts +125 -0
  74. package/src/harness/log-delta.ts +100 -0
  75. package/src/harness/main.test.ts +211 -0
  76. package/src/harness/main.ts +196 -0
  77. package/src/harness/methods.test.ts +63 -0
  78. package/src/harness/methods.ts +92 -0
  79. package/src/harness/names-registry.test.ts +137 -0
  80. package/src/harness/names-registry.ts +108 -0
  81. package/src/harness/protocol.test.ts +148 -0
  82. package/src/harness/protocol.ts +163 -0
  83. package/src/harness/ready-poll.test.ts +172 -0
  84. package/src/harness/ready-poll.ts +93 -0
  85. package/src/harness/service-graph.test.ts +97 -0
  86. package/src/harness/service-graph.ts +97 -0
  87. package/src/harness/volume-paths.test.ts +102 -0
  88. package/src/harness/volume-paths.ts +112 -0
  89. package/src/ids.ts +89 -0
  90. package/src/index.ts +2767 -0
  91. package/src/ingress.ts +305 -0
  92. package/src/inspect.ts +739 -0
  93. package/src/locator.ts +716 -0
  94. package/src/mobile.ts +138 -0
  95. package/src/record-secrets.ts +41 -0
  96. package/src/recorder.ts +856 -0
  97. package/src/redis.ts +202 -0
  98. package/src/replay-bundle.ts +108 -0
  99. package/src/resolver.ts +348 -0
  100. package/src/s3.ts +333 -0
  101. package/src/sql.ts +243 -0
  102. package/src/terminal.ts +740 -0
  103. package/src/url-match.ts +67 -0
  104. package/src/vendor/rrweb-plugin-console-record.umd.js +521 -0
  105. package/src/vendor/rrweb-record.min.js +5061 -0
@@ -0,0 +1,132 @@
1
+ import type { ServiceDefinition, ServiceSetupContext } from "../index.js";
2
+ import { SQL, type SqlClient } from "../sql.js";
3
+
4
+ export interface PostgresOptions {
5
+ /** Image tag for the official `postgres` image. Default `"18-alpine"`.
6
+ * Ignored when {@link image} is set. */
7
+ version?: string;
8
+ /**
9
+ * Full image reference, overriding the default `postgres:<version>`. For a
10
+ * Bun-SQL-/wire-compatible image (timescaledb, postgis, pgvector, …) you
11
+ * still get the instrumented client on `ctx.svc.<name>.client`.
12
+ */
13
+ image?: string;
14
+ /** Database created on first boot. */
15
+ database: string;
16
+ /** Superuser name created on first boot. */
17
+ user: string;
18
+ /** Superuser password. */
19
+ password: string;
20
+ /**
21
+ * Whether postgres data persists across container restarts via a bind
22
+ * mount under `.spectest/volumes/<name>/`. Default `true`.
23
+ * Snapshots/forks always preserve state regardless of this flag — the
24
+ * volume just means a plain `docker rm`/`docker run` cycle keeps data.
25
+ */
26
+ persistent?: boolean;
27
+ /** TCP port the container listens on. Default `5432`. */
28
+ port?: number;
29
+ /**
30
+ * CMD args appended after the image entrypoint (keeps the entrypoint, unlike
31
+ * `command`). For extension tuning, e.g.
32
+ * `["postgres", "-c", "timescaledb.max_background_workers=0"]`.
33
+ */
34
+ args?: string[];
35
+ /** Extra environment variables forwarded to the container. */
36
+ env?: Record<string, string>;
37
+ /**
38
+ * One-shot hook that runs after the ready probe passes, before any
39
+ * dependent service starts and before any test. This is where schema
40
+ * and seed data go: the daemon captures the result into the
41
+ * warm-template snapshot, so it never runs again on a warm start or a
42
+ * fork.
43
+ *
44
+ * The argument is the full test context plus this service's `name` and
45
+ * its {@link PostgresHelpers}, so the instrumented client is already
46
+ * built:
47
+ *
48
+ * ```ts
49
+ * db: postgres({
50
+ * database: "todos", user: "todos", password: "todos",
51
+ * setup: async ({ helpers }) => {
52
+ * await helpers.client`CREATE TABLE todos (
53
+ * id SERIAL PRIMARY KEY, text TEXT NOT NULL)`;
54
+ * },
55
+ * }),
56
+ * ```
57
+ */
58
+ setup?: (args: ServiceSetupContext<PostgresHelpers>) => void | Promise<void>;
59
+ }
60
+
61
+ /** Helpers a `postgres(...)` service exposes on `ctx.svc.<name>`. */
62
+ export interface PostgresHelpers {
63
+ /** An instrumented Bun SQL client — each query lands on the test event log
64
+ * alongside http/exec/assertion events, and its rows come back
65
+ * inspect-wrapped so `expect(...)` on them links to the query. See
66
+ * {@link SQL}. */
67
+ client: SqlClient;
68
+ }
69
+
70
+ /**
71
+ * A ready-to-use Postgres service. Drop into `environment.services`:
72
+ *
73
+ * ```ts
74
+ * services: {
75
+ * db: postgres({ database: "todos", user: "todos", password: "todos" }),
76
+ * ...
77
+ * }
78
+ * ```
79
+ *
80
+ * Peer services reach it at `<key>:<port>` (e.g. `db:5432` for the
81
+ * example above). Tests get a wired-up Bun SQL client at
82
+ * `ctx.svc.<key>.client` — `await ctx.svc.db.client\`SELECT 1\`` — with
83
+ * every query recorded on the test event log.
84
+ *
85
+ * Point it at a wire-compatible image with `image`/`args`:
86
+ *
87
+ * ```ts
88
+ * db: postgres({
89
+ * image: "timescale/timescaledb:latest-pg17",
90
+ * args: ["postgres", "-c", "timescaledb.max_background_workers=0"],
91
+ * database: "app", user: "app", password: "app",
92
+ * }),
93
+ * ```
94
+ */
95
+ export function postgres(opts: PostgresOptions) {
96
+ const version = opts.version ?? "18-alpine";
97
+ const reference = opts.image ?? `postgres:${version}`;
98
+ const port = opts.port ?? 5432;
99
+ const persistent = opts.persistent ?? true;
100
+ // `satisfies` (instead of a return-type annotation) preserves the
101
+ // literal type — in particular, the `helpers` factory's return shape.
102
+ // The mapped type in `ServiceHandlesFor<S>` reads that to type
103
+ // `ctx.svc.<name>` as `{ client: SqlClient }`.
104
+ return {
105
+ image: { type: "registry", reference },
106
+ ...(opts.args ? { args: opts.args } : {}),
107
+ env: {
108
+ POSTGRES_DB: opts.database,
109
+ POSTGRES_USER: opts.user,
110
+ POSTGRES_PASSWORD: opts.password,
111
+ // PGDATA lives in a subdir so postgres can initialise inside a bind
112
+ // mount that may not be empty on first boot.
113
+ PGDATA: "/var/lib/postgresql/data/pgdata",
114
+ ...(opts.env ?? {}),
115
+ },
116
+ volumes: persistent ? [{ target: "/var/lib/postgresql/data" }] : [],
117
+ ports: [port],
118
+ readyCheck: { type: "tcp" as const, port, timeoutSecs: 60 },
119
+ helpers: ({ name }: { name: string }): PostgresHelpers => {
120
+ const url =
121
+ `postgres://${encodeURIComponent(opts.user)}` +
122
+ `:${encodeURIComponent(opts.password)}` +
123
+ `@${name}:${port}/${encodeURIComponent(opts.database)}`;
124
+ return { client: new SQL(url, { label: name }) };
125
+ },
126
+ // The user's hook, forwarded verbatim — postgres() declares none of
127
+ // its own. If it ever gains one, CHAIN the user's after it (the way
128
+ // `serviceGroup` chains a group hook after the primary part's) rather
129
+ // than letting either one win.
130
+ ...(opts.setup ? { setup: opts.setup } : {}),
131
+ } satisfies ServiceDefinition<PostgresHelpers>;
132
+ }