@tencildev/testing 0.1.1 → 0.2.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/README.md CHANGED
@@ -11,6 +11,7 @@ npm install --save-dev @tencildev/testing
11
11
  - **`FakeT3Server`**: a stand-in T3 Code server (auth endpoints and the RPC
12
12
  WebSocket) that simulates streamed agent turns.
13
13
  - **`FakeAgentSdk`**: a stand-in for `@anthropic-ai/claude-agent-sdk`.
14
+ - **`FakeRegistry`**: a stand-in npm registry that answers Tencil's `latest` version.
14
15
  - **`waitFor`**: poll until a condition holds.
15
16
 
16
17
  ```ts
package/dist/index.d.mts CHANGED
@@ -116,6 +116,28 @@ export declare class FakeAgentSdk {
116
116
  getSessionMessages: (id: string) => Promise<Record<string, unknown>[]>;
117
117
  }
118
118
  //#endregion
119
+ //#region src/fake-registry.d.ts
120
+ interface FakeRegistryOptions {
121
+ /** What `GET /tencil/latest` answers; unset answers 404, like an unpublished package. */
122
+ latest?: string;
123
+ port?: number;
124
+ }
125
+ /**
126
+ * A stand-in for the npm registry that only knows Tencil's `latest` tag.
127
+ * Anything else, such as npm fetching the package to install it, gets a 404.
128
+ */
129
+ export declare class FakeRegistry {
130
+ #private;
131
+ /** Change it to publish a new version. */
132
+ latest: string | undefined;
133
+ /** Paths asked for, oldest first. */
134
+ readonly requests: string[];
135
+ private constructor();
136
+ static start(options?: FakeRegistryOptions): Promise<FakeRegistry>;
137
+ get url(): string;
138
+ close(): Promise<void>;
139
+ }
140
+ //#endregion
119
141
  //#region src/fake-t3-server.d.ts
120
142
  /**
121
143
  * A small stand-in for a T3 Code server: the HTTP auth endpoints, the shell
@@ -233,4 +255,4 @@ export declare function waitFor<T>(check: () => T | undefined | null | false | P
233
255
  message?: string | undefined;
234
256
  }): Promise<T>;
235
257
  //#endregion
236
- export type { FakeAgentProviderOptions, FakeMessage, FakeProject, FakeProvider, FakeQueryRecord, FakeSession, FakeT3Options, FakeThread };
258
+ export type { FakeAgentProviderOptions, FakeMessage, FakeProject, FakeProvider, FakeQueryRecord, FakeRegistryOptions, FakeSession, FakeT3Options, FakeThread };
package/dist/index.mjs CHANGED
@@ -283,6 +283,50 @@ function textOf(content) {
283
283
  return content.filter((block) => block.type === "text").map((block) => block.text).join("\n\n");
284
284
  }
285
285
  //#endregion
286
+ //#region src/fake-registry.ts
287
+ /**
288
+ * A stand-in for the npm registry that only knows Tencil's `latest` tag.
289
+ * Anything else, such as npm fetching the package to install it, gets a 404.
290
+ */
291
+ var FakeRegistry = class FakeRegistry {
292
+ /** Change it to publish a new version. */
293
+ latest;
294
+ /** Paths asked for, oldest first. */
295
+ requests = [];
296
+ #http;
297
+ #port = 0;
298
+ constructor(options) {
299
+ this.latest = options.latest;
300
+ this.#http = createServer((request, response) => {
301
+ const path = new URL(request.url ?? "/", "http://localhost").pathname;
302
+ this.requests.push(path);
303
+ if (path === "/tencil/latest" && this.latest) {
304
+ response.writeHead(200, { "content-type": "application/json" });
305
+ response.end(JSON.stringify({
306
+ name: "tencil",
307
+ version: this.latest
308
+ }));
309
+ return;
310
+ }
311
+ response.writeHead(404, { "content-type": "application/json" });
312
+ response.end(JSON.stringify({ error: "Not found" }));
313
+ });
314
+ }
315
+ static async start(options = {}) {
316
+ const registry = new FakeRegistry(options);
317
+ await new Promise((resolve) => registry.#http.listen(options.port ?? 0, "127.0.0.1", resolve));
318
+ const address = registry.#http.address();
319
+ registry.#port = typeof address === "object" && address ? address.port : 0;
320
+ return registry;
321
+ }
322
+ get url() {
323
+ return `http://127.0.0.1:${this.#port}`;
324
+ }
325
+ close() {
326
+ return new Promise((resolve) => this.#http.close(() => resolve()));
327
+ }
328
+ };
329
+ //#endregion
286
330
  //#region src/fake-t3-server.ts
287
331
  const CODEX_PROVIDER = {
288
332
  instanceId: "codex",
@@ -843,4 +887,4 @@ async function waitFor(check, { timeoutMs = 3e3, intervalMs = 10, message = "con
843
887
  throw new Error(`Timed out waiting for ${message}${last ? `: ${String(last)}` : ""}`);
844
888
  }
845
889
  //#endregion
846
- export { CODEX_PROVIDER, FakeAgentProvider, FakeAgentSdk, FakeT3Server, waitFor };
890
+ export { CODEX_PROVIDER, FakeAgentProvider, FakeAgentSdk, FakeRegistry, FakeT3Server, waitFor };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tencildev/testing",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "description": "Test doubles for Tencil: a fake provider, a fake T3 Code server and a fake Claude Agent SDK.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Pixel Perfect Agency",
@@ -33,7 +33,7 @@
33
33
  },
34
34
  "dependencies": {
35
35
  "ws": "^8.22.0",
36
- "@tencildev/protocol": "^0.2.0"
36
+ "@tencildev/protocol": "^0.4.0"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@types/ws": "^8.18.2",