@levr-one/auth 1.1.7 → 1.1.9
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/dist/config-watcher.test.js +4 -0
- package/dist/config-watcher.test.js.map +1 -1
- package/dist/config.d.ts +1 -78
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +14 -247
- package/dist/config.js.map +1 -1
- package/dist/local-env.d.ts +170 -0
- package/dist/local-env.d.ts.map +1 -0
- package/dist/local-env.js +368 -0
- package/dist/local-env.js.map +1 -0
- package/dist/local-env.test.d.ts +2 -0
- package/dist/local-env.test.d.ts.map +1 -0
- package/dist/local-env.test.js +138 -0
- package/dist/local-env.test.js.map +1 -0
- package/dist/status-report.d.ts.map +1 -1
- package/dist/status-report.js +6 -1
- package/dist/status-report.js.map +1 -1
- package/dist/status-report.test.js +28 -0
- package/dist/status-report.test.js.map +1 -1
- package/dist/test-utils.js +3 -3
- package/dist/test-utils.js.map +1 -1
- package/dist/token-store.d.ts +5 -0
- package/dist/token-store.d.ts.map +1 -1
- package/dist/token-store.js +11 -0
- package/dist/token-store.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local-checkout environment resolution: which backend, auth-web and client a
|
|
3
|
+
* checkout of this monorepo serves, read from its own `apps/backender` env.
|
|
4
|
+
*
|
|
5
|
+
* A LEAF module on purpose: it imports nothing else from this package (the
|
|
6
|
+
* `TqConfig` import is type-only and erased), so both `config.ts` and
|
|
7
|
+
* `token-store.ts` can use it without the import cycle `token-store.ts` exists
|
|
8
|
+
* to avoid (`config.ts` imports `token-store.ts`). internal moved these
|
|
9
|
+
* helpers here from `config.ts`, which still re-exports the public ones.
|
|
10
|
+
*/
|
|
11
|
+
import * as fs from 'fs';
|
|
12
|
+
import * as path from 'path';
|
|
13
|
+
/**
|
|
14
|
+
* Returns true when running inside a test runner (Vitest, Jest, etc.).
|
|
15
|
+
*/
|
|
16
|
+
export function isTestEnv() {
|
|
17
|
+
return (process.env.VITEST !== undefined ||
|
|
18
|
+
process.env.NODE_ENV === 'test' ||
|
|
19
|
+
process.env.JEST_WORKER_ID !== undefined);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Detect whether the developer is running in TLS dev mode (mkcert + DEV_TLS).
|
|
23
|
+
*
|
|
24
|
+
* Resolution order:
|
|
25
|
+
* 1. Tests (Vitest/Jest/NODE_ENV=test) → always false (deterministic).
|
|
26
|
+
* 2. Explicit `DEV_TLS` env var → 'true'/'false' wins.
|
|
27
|
+
* 3. `DEV_TLS` in the backender's env → the setting that actually decides
|
|
28
|
+
* whether the backender serves TLS.
|
|
29
|
+
*
|
|
30
|
+
* Step 3 used to probe for `apps/backender/certs/dev.crt` and treat its
|
|
31
|
+
* PRESENCE as "TLS is on". That tested a proxy for the real question: the cert
|
|
32
|
+
* is written once by scripts/dev-setup-tls.sh and never removed when TLS is
|
|
33
|
+
* turned off, so any machine that had ever run it resolved TLS mode forever.
|
|
34
|
+
*
|
|
35
|
+
* The walk-up from cwd is retained, so this still works from the repo root, an
|
|
36
|
+
* app subdirectory, or a worktree.
|
|
37
|
+
*
|
|
38
|
+
* Keep in sync with `apps/sync-server/src/auth.ts:isLocalTlsMode()` — the two
|
|
39
|
+
* are duplicated verbatim (sync-server does not depend on this package). The
|
|
40
|
+
* bodies are kept byte-identical so a plain `diff` verifies the claim; that is
|
|
41
|
+
* also why the quote check below is split across lines, since this package
|
|
42
|
+
* formats at printWidth 80 and sync-server at 100.
|
|
43
|
+
*/
|
|
44
|
+
export function isLocalTlsMode() {
|
|
45
|
+
if (isTestEnv())
|
|
46
|
+
return false;
|
|
47
|
+
if (process.env.DEV_TLS === 'true')
|
|
48
|
+
return true;
|
|
49
|
+
if (process.env.DEV_TLS === 'false')
|
|
50
|
+
return false;
|
|
51
|
+
return devTlsFromBackenderEnv();
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* `parseDevTls` reproduces three dotenv behaviours the obvious regex gets
|
|
55
|
+
* wrong. Each failed CLOSED — it missed a real `DEV_TLS=true` and so dialled
|
|
56
|
+
* http:// at a TLS backender, the exact bug this file exists to fix, mirrored:
|
|
57
|
+
* - `export DEV_TLS=true` — the form docs/guides/dev-tls-setup.md prints
|
|
58
|
+
* - `DEV_TLS=true # note` — trailing comment on an unquoted value
|
|
59
|
+
* - the key repeated — dotenv takes the LAST occurrence, not the first
|
|
60
|
+
*
|
|
61
|
+
* dotenv itself is not used: `packages/auth` does not depend on it, and this
|
|
62
|
+
* helper is duplicated verbatim between the two files (see the note above).
|
|
63
|
+
*/
|
|
64
|
+
export function parseDevTls(contents) {
|
|
65
|
+
// Global: the LAST assignment wins, matching dotenv.
|
|
66
|
+
const re = /^[ \t]*(?:export[ \t]+)?DEV_TLS[ \t]*=[ \t]*(.*)$/gm;
|
|
67
|
+
let raw;
|
|
68
|
+
for (const m of contents.matchAll(re))
|
|
69
|
+
raw = m[1];
|
|
70
|
+
if (raw === undefined)
|
|
71
|
+
return undefined;
|
|
72
|
+
let value = raw.trim();
|
|
73
|
+
const quote = value[0];
|
|
74
|
+
const isQuote = quote === '"' || quote === "'";
|
|
75
|
+
if (isQuote && value.length > 1 && value.endsWith(quote)) {
|
|
76
|
+
value = value.slice(1, -1);
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
// Unquoted only: everything from `#` onward is a comment.
|
|
80
|
+
value = (value.split('#')[0] ?? '').trim();
|
|
81
|
+
}
|
|
82
|
+
return value === 'true';
|
|
83
|
+
}
|
|
84
|
+
function devTlsFromBackenderEnv() {
|
|
85
|
+
let dir = process.cwd();
|
|
86
|
+
for (let i = 0; i < 10; i++) {
|
|
87
|
+
// `.env.worktree` FIRST — it outranks `.env` for the backender, because
|
|
88
|
+
// apps/backender/src/env.ts loads it first and dotenv does not overwrite
|
|
89
|
+
// an already-set key. Reading only `.env` resolves the wrong protocol in a
|
|
90
|
+
// worktree that overrides DEV_TLS.
|
|
91
|
+
for (const name of ['.env.worktree', '.env']) {
|
|
92
|
+
const envPath = path.join(dir, 'apps/backender', name);
|
|
93
|
+
if (!fs.existsSync(envPath))
|
|
94
|
+
continue;
|
|
95
|
+
try {
|
|
96
|
+
const parsed = parseDevTls(fs.readFileSync(envPath, 'utf8'));
|
|
97
|
+
if (parsed !== undefined)
|
|
98
|
+
return parsed;
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
// Unreadable env file must not silently select TLS — fail safe.
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
const parent = path.dirname(dir);
|
|
106
|
+
if (parent === dir)
|
|
107
|
+
break;
|
|
108
|
+
dir = parent;
|
|
109
|
+
}
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Accept an env value ONLY if it is a bare `http(s)` origin — scheme, host,
|
|
114
|
+
* optional port, and nothing else. Returns the normalised origin, or
|
|
115
|
+
* `undefined` for anything that is not one.
|
|
116
|
+
*
|
|
117
|
+
* This exists because `API_BASE_URL` does not mean the same thing in every
|
|
118
|
+
* env file. In a worktree's `apps/backender/.env` it is that backender's own
|
|
119
|
+
* origin (`http://localhost:8580`) — the value `tq:env local` wants. In the
|
|
120
|
+
* main checkout under DEV_TLS it is `https://ai.levr.test:3020/api`, the URL
|
|
121
|
+
* the BROWSER should call: the client SPA's `/api` proxy. Accepting the
|
|
122
|
+
* second overwrote a correctly-computed `LOCAL_HTTPS` preset with a value
|
|
123
|
+
* that was wrong twice over — wrong host role, and a client dev-server port
|
|
124
|
+
* that is usually not listening — so every stdio MCP server dialled a dead
|
|
125
|
+
* host and reported an opaque `fetch failed`.
|
|
126
|
+
*
|
|
127
|
+
* The path is the discriminator **for the local checkout specifically** — the
|
|
128
|
+
* name says `Local` for that reason. It is NOT a universal truth that a
|
|
129
|
+
* backend base URL has no path: this repo's own deploys set
|
|
130
|
+
* `API_BASE_URL=https://ai.levr.now/api` (`apps/backender/chart/stage.yaml:35`)
|
|
131
|
+
* and `https://ai.levr.one/api` (`chart/prod.yaml:74`), and `setup-mcp.ts`
|
|
132
|
+
* deliberately accepts that shape because the levr MCP endpoint IS reached
|
|
133
|
+
* through the SPA proxy. Do not reuse this helper where deployed values are
|
|
134
|
+
* in scope — it would reject a valid production URL. internal.
|
|
135
|
+
*
|
|
136
|
+
* It fails SAFE — anything ambiguous declines to override the preset instead
|
|
137
|
+
* of silently replacing it. Do NOT weaken this back to a `^https?://` prefix
|
|
138
|
+
* test; that is precisely the check the proxy URL passed.
|
|
139
|
+
*
|
|
140
|
+
* Kept here rather than in `cli.ts` because that module is a self-executing
|
|
141
|
+
* CLI (importing it runs the command switch), so a pure helper there cannot
|
|
142
|
+
* be unit-tested — the same reason `parseDevTls` lives in this file.
|
|
143
|
+
*
|
|
144
|
+
* internal.
|
|
145
|
+
*/
|
|
146
|
+
export function parseLocalBackenderOrigin(raw) {
|
|
147
|
+
if (raw === undefined)
|
|
148
|
+
return undefined;
|
|
149
|
+
const trimmed = raw.trim().replace(/\/+$/, '');
|
|
150
|
+
if (!trimmed)
|
|
151
|
+
return undefined;
|
|
152
|
+
// Reject on the RAW text, BEFORE parsing. WHATWG normalises during parse:
|
|
153
|
+
// `/foo/..` collapses to `/`, and a bare trailing `?` or `#` reports an
|
|
154
|
+
// EMPTY `search`/`hash`. A guard that reads only the parsed URL therefore
|
|
155
|
+
// cannot see the two shapes it most needs to reject — which is precisely
|
|
156
|
+
// the bug the first cut of this function shipped (internal): it validated
|
|
157
|
+
// `parsed` and then returned the raw string.
|
|
158
|
+
if (/[?#]/.test(trimmed))
|
|
159
|
+
return undefined;
|
|
160
|
+
// WHATWG also reads `\\` as `/` for http(s), so `http:\\host\\x` would
|
|
161
|
+
// slip past the raw-path check below; and any `@` is userinfo, which never
|
|
162
|
+
// belongs here (an EMPTY one, `http://@host`, parses to no credentials and
|
|
163
|
+
// would otherwise pass the check further down). internal review F-001.
|
|
164
|
+
if (/[\\@]/.test(trimmed))
|
|
165
|
+
return undefined;
|
|
166
|
+
const afterScheme = trimmed.replace(/^https?:\/\//i, '');
|
|
167
|
+
if (afterScheme.includes('/'))
|
|
168
|
+
return undefined;
|
|
169
|
+
let parsed;
|
|
170
|
+
try {
|
|
171
|
+
parsed = new URL(trimmed);
|
|
172
|
+
}
|
|
173
|
+
catch {
|
|
174
|
+
return undefined;
|
|
175
|
+
}
|
|
176
|
+
if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {
|
|
177
|
+
return undefined;
|
|
178
|
+
}
|
|
179
|
+
// Credentials never belong in a backend base URL, and silently stripping
|
|
180
|
+
// them would write a different URL than the author wrote.
|
|
181
|
+
if (parsed.username || parsed.password)
|
|
182
|
+
return undefined;
|
|
183
|
+
// Return the PARSED origin, never the raw text — that pairing is what makes
|
|
184
|
+
// the guards above load-bearing rather than decorative.
|
|
185
|
+
return parsed.origin;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Read one key out of dotenv file contents, reproducing the behaviours
|
|
189
|
+
* `parseDevTls` documents twenty lines above: an `export ` prefix, a trailing
|
|
190
|
+
* `#` comment on an unquoted value, and the LAST assignment winning when the
|
|
191
|
+
* key repeats. Quotes are stripped only when they PAIR, so an unbalanced
|
|
192
|
+
* quote is left intact rather than half-removed.
|
|
193
|
+
*
|
|
194
|
+
* The first cut of this reader hand-rolled a narrower regex and inherited
|
|
195
|
+
* none of that, even though the repo had already been bitten by the `export `
|
|
196
|
+
* form on this very key — see `scripts/worktree-delete.test.ts:319`.
|
|
197
|
+
* internal / internal.
|
|
198
|
+
*
|
|
199
|
+
* `key` is always a literal from the call sites, never user input, so
|
|
200
|
+
* interpolating it into the pattern is safe.
|
|
201
|
+
*/
|
|
202
|
+
export function extractEnvValue(contents, key) {
|
|
203
|
+
const re = new RegExp(`^[ \\t]*(?:export[ \\t]+)?${key}[ \\t]*=[ \\t]*(.*)$`, 'gm');
|
|
204
|
+
let raw;
|
|
205
|
+
for (const m of contents.matchAll(re))
|
|
206
|
+
raw = m[1];
|
|
207
|
+
if (raw === undefined)
|
|
208
|
+
return undefined;
|
|
209
|
+
let value = raw.trim();
|
|
210
|
+
const quote = value[0];
|
|
211
|
+
const isQuote = quote === '"' || quote === "'";
|
|
212
|
+
if (isQuote && value.length > 1 && value.endsWith(quote)) {
|
|
213
|
+
value = value.slice(1, -1);
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
value = (value.split('#')[0] ?? '').trim();
|
|
217
|
+
}
|
|
218
|
+
return value;
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Resolve a backender origin across the env files in precedence order, given
|
|
222
|
+
* their CONTENTS (`undefined` for a file that does not exist). Pure, so the
|
|
223
|
+
* precedence rule is unit-testable — the file I/O stays in `cli.ts`.
|
|
224
|
+
*
|
|
225
|
+
* **The first file that CONTAINS the key decides, even if its value is
|
|
226
|
+
* unusable.** That matches dotenv and `devTlsFromBackenderEnv`, which both
|
|
227
|
+
* fall through only on an ABSENT key. The first cut fell through on absent
|
|
228
|
+
* OR unusable, which let `.env.worktree` and `.env` disagree: the backender
|
|
229
|
+
* would use the higher-precedence value while the CLI silently resolved the
|
|
230
|
+
* lower one. Two answers for one key is exactly what reading these files in
|
|
231
|
+
* a shared order exists to prevent. Falling back to the preset is the safe
|
|
232
|
+
* direction; falling back to a different file is not. internal.
|
|
233
|
+
*/
|
|
234
|
+
export function resolveOriginFromEnvFiles(key, files) {
|
|
235
|
+
for (const contents of files) {
|
|
236
|
+
if (contents === undefined)
|
|
237
|
+
continue;
|
|
238
|
+
const raw = extractEnvValue(contents, key);
|
|
239
|
+
if (raw === undefined)
|
|
240
|
+
continue;
|
|
241
|
+
return parseLocalBackenderOrigin(raw);
|
|
242
|
+
}
|
|
243
|
+
return undefined;
|
|
244
|
+
}
|
|
245
|
+
export const LOCAL_HTTP = {
|
|
246
|
+
environment: 'local',
|
|
247
|
+
apiUrl: 'http://localhost:8080',
|
|
248
|
+
authUrl: 'http://localhost:3021',
|
|
249
|
+
clientUrl: 'http://localhost:3020',
|
|
250
|
+
oauthClientId: '2',
|
|
251
|
+
};
|
|
252
|
+
export const LOCAL_HTTPS = {
|
|
253
|
+
environment: 'local',
|
|
254
|
+
// internal D14: TLS dev mode mirrors the prod parent-domain topology
|
|
255
|
+
// (`*.levr.test` is the dev counterpart of `*.levr.now` / `*.levr.one`).
|
|
256
|
+
// The mkcert cert generated by scripts/dev-setup-tls.sh covers these
|
|
257
|
+
// hostnames, /etc/hosts entries are written by the same script, and the
|
|
258
|
+
// SPA's `runtime-config.ts` falls back to the same triple. Keeping the
|
|
259
|
+
// names consistent end-to-end means cookies set with `Domain=.levr.test`
|
|
260
|
+
// travel to all three subdomains the same way they do in prod.
|
|
261
|
+
apiUrl: 'https://api.levr.test:8080',
|
|
262
|
+
authUrl: 'https://auth.levr.test:3021',
|
|
263
|
+
clientUrl: 'https://ai.levr.test:3020',
|
|
264
|
+
oauthClientId: '2',
|
|
265
|
+
};
|
|
266
|
+
/** Env files the backender reads, in its own precedence order. */
|
|
267
|
+
const BACKENDER_ENV_FILES = ['.env.worktree', '.env'];
|
|
268
|
+
/**
|
|
269
|
+
* The checkout a reader belongs to: the nearest ancestor of `start` with an
|
|
270
|
+
* `apps/backender` env file, or undefined outside any checkout (e.g. the
|
|
271
|
+
* published CLI run in an unrelated project).
|
|
272
|
+
*
|
|
273
|
+
* Walks up like `devTlsFromBackenderEnv`, so a reader started from an app
|
|
274
|
+
* subdirectory still finds its checkout. The stdio MCP servers are started
|
|
275
|
+
* from the checkout root (`./plugins/...` in `.mcp.json`) and the hooks from
|
|
276
|
+
* `$CLAUDE_PROJECT_DIR`, so for them `start` IS the session's checkout.
|
|
277
|
+
*/
|
|
278
|
+
export function findLocalCheckoutRoot(start) {
|
|
279
|
+
let dir = path.resolve(start);
|
|
280
|
+
for (let i = 0; i < 10; i++) {
|
|
281
|
+
const hasEnv = BACKENDER_ENV_FILES.some((name) => fs.existsSync(path.join(dir, 'apps', 'backender', name)));
|
|
282
|
+
if (hasEnv)
|
|
283
|
+
return dir;
|
|
284
|
+
const parent = path.dirname(dir);
|
|
285
|
+
if (parent === dir)
|
|
286
|
+
break;
|
|
287
|
+
dir = parent;
|
|
288
|
+
}
|
|
289
|
+
return undefined;
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Resolve the `local` environment for the checkout containing `start`.
|
|
293
|
+
*
|
|
294
|
+
* `local` means "the backend of the checkout I am working in". `tq:env local`
|
|
295
|
+
* still writes the URLs it resolved into the machine-global
|
|
296
|
+
* `~/.tq/config.json` (older readers and the published CLI read them), but
|
|
297
|
+
* every reader in this package re-resolves `local` HERE, against its own
|
|
298
|
+
* checkout, so running `tq:env local` in one worktree no longer re-points the
|
|
299
|
+
* sessions of every other checkout on the machine. internal.
|
|
300
|
+
*
|
|
301
|
+
* Per checkout:
|
|
302
|
+
* - all three URLs come from `apps/backender`'s env (`API_BASE_URL`,
|
|
303
|
+
* `AUTH_URL`, `CLIENT_APP_URL`), which `worktree-add.sh` writes together
|
|
304
|
+
* when it allocates a worktree's port block — resolving only the API left
|
|
305
|
+
* `tq:login` opening another checkout's auth-web;
|
|
306
|
+
* - `.env.worktree` before `.env`, the order `apps/backender/src/env.ts`
|
|
307
|
+
* loads them, and the first file that HAS a key decides
|
|
308
|
+
* (`resolveOriginFromEnvFiles`);
|
|
309
|
+
* - only a bare origin is accepted (`parseLocalBackenderOrigin`): the main
|
|
310
|
+
* checkout under DEV_TLS carries the SPA's `/api` proxy URL there, which
|
|
311
|
+
* must fall back to the preset, not be dialled (internal);
|
|
312
|
+
* - otherwise the local preset, HTTPS when this checkout runs DEV_TLS.
|
|
313
|
+
*
|
|
314
|
+
* This is deliberately STRICTER than `scripts/setup-mcp.ts`'s
|
|
315
|
+
* `resolveLocalLevrUrl`, which takes any `https?://` value: the levr MCP
|
|
316
|
+
* endpoint is legitimately reached THROUGH the SPA proxy, so it wants the
|
|
317
|
+
* `/api` suffix this must reject. Not drift to reconcile — "fixing" it
|
|
318
|
+
* reintroduces internal. internal.
|
|
319
|
+
*
|
|
320
|
+
* Returns undefined outside a checkout, so the caller keeps the stored URLs.
|
|
321
|
+
*/
|
|
322
|
+
export function resolveLocalCheckout(start = process.cwd()) {
|
|
323
|
+
const root = findLocalCheckoutRoot(start);
|
|
324
|
+
if (!root)
|
|
325
|
+
return undefined;
|
|
326
|
+
// Per file, so one unreadable file does not discard the other — the
|
|
327
|
+
// backender would still read it.
|
|
328
|
+
const files = BACKENDER_ENV_FILES.map((name) => {
|
|
329
|
+
const envPath = path.join(root, 'apps', 'backender', name);
|
|
330
|
+
try {
|
|
331
|
+
return fs.existsSync(envPath)
|
|
332
|
+
? fs.readFileSync(envPath, 'utf8')
|
|
333
|
+
: undefined;
|
|
334
|
+
}
|
|
335
|
+
catch {
|
|
336
|
+
return undefined;
|
|
337
|
+
}
|
|
338
|
+
});
|
|
339
|
+
const preset = checkoutUsesTls(files) ? LOCAL_HTTPS : LOCAL_HTTP;
|
|
340
|
+
return {
|
|
341
|
+
root,
|
|
342
|
+
apiUrl: resolveOriginFromEnvFiles('API_BASE_URL', files) ?? preset.apiUrl,
|
|
343
|
+
authUrl: resolveOriginFromEnvFiles('AUTH_URL', files) ?? preset.authUrl,
|
|
344
|
+
clientUrl: resolveOriginFromEnvFiles('CLIENT_APP_URL', files) ?? preset.clientUrl,
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* `isLocalTlsMode()` for an explicit checkout's env files rather than a cwd
|
|
349
|
+
* walk: tests first, then the `DEV_TLS` env var, then the first file that
|
|
350
|
+
* sets `DEV_TLS`. Same order, same parser.
|
|
351
|
+
*/
|
|
352
|
+
function checkoutUsesTls(files) {
|
|
353
|
+
if (isTestEnv())
|
|
354
|
+
return false;
|
|
355
|
+
if (process.env.DEV_TLS === 'true')
|
|
356
|
+
return true;
|
|
357
|
+
if (process.env.DEV_TLS === 'false')
|
|
358
|
+
return false;
|
|
359
|
+
for (const contents of files) {
|
|
360
|
+
if (contents === undefined)
|
|
361
|
+
continue;
|
|
362
|
+
const parsed = parseDevTls(contents);
|
|
363
|
+
if (parsed !== undefined)
|
|
364
|
+
return parsed;
|
|
365
|
+
}
|
|
366
|
+
return false;
|
|
367
|
+
}
|
|
368
|
+
//# sourceMappingURL=local-env.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local-env.js","sourceRoot":"","sources":["../src/local-env.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAI7B;;GAEG;AACH,MAAM,UAAU,SAAS;IACvB,OAAO,CACL,OAAO,CAAC,GAAG,CAAC,MAAM,KAAK,SAAS;QAChC,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,MAAM;QAC/B,OAAO,CAAC,GAAG,CAAC,cAAc,KAAK,SAAS,CACzC,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,UAAU,cAAc;IAC5B,IAAI,SAAS,EAAE;QAAE,OAAO,KAAK,CAAC;IAC9B,IAAI,OAAO,CAAC,GAAG,CAAC,OAAO,KAAK,MAAM;QAAE,OAAO,IAAI,CAAC;IAChD,IAAI,OAAO,CAAC,GAAG,CAAC,OAAO,KAAK,OAAO;QAAE,OAAO,KAAK,CAAC;IAClD,OAAO,sBAAsB,EAAE,CAAC;AAClC,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,WAAW,CAAC,QAAgB;IAC1C,qDAAqD;IACrD,MAAM,EAAE,GAAG,qDAAqD,CAAC;IACjE,IAAI,GAAuB,CAAC;IAC5B,KAAK,MAAM,CAAC,IAAI,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;QAAE,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAClD,IAAI,GAAG,KAAK,SAAS;QAAE,OAAO,SAAS,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AAS,EACP,yBAAyB,CAAC,gBAAgB,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,SAAS;KACzE,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,SAAS,eAAe,CAAC,KAAsC;IAC7D,IAAI,SAAS,EAAE;QAAE,OAAO,KAAK,CAAC;IAC9B,IAAI,OAAO,CAAC,GAAG,CAAC,OAAO,KAAK,MAAM;QAAE,OAAO,IAAI,CAAC;IAChD,IAAI,OAAO,CAAC,GAAG,CAAC,OAAO,KAAK,OAAO;QAAE,OAAO,KAAK,CAAC;IAClD,KAAK,MAAM,QAAQ,IAAI,KAAK,EAAE,CAAC;QAC7B,IAAI,QAAQ,KAAK,SAAS;YAAE,SAAS;QACrC,MAAM,MAAM,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAC;QACrC,IAAI,MAAM,KAAK,SAAS;YAAE,OAAO,MAAM,CAAC;IAC1C,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local-env.test.d.ts","sourceRoot":"","sources":["../src/local-env.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
|
|
2
|
+
import * as fs from 'fs';
|
|
3
|
+
import * as path from 'path';
|
|
4
|
+
import * as os from 'os';
|
|
5
|
+
const state = vi.hoisted(() => ({ tmpDir: '' }));
|
|
6
|
+
// token-store's TQ_DIR is derived from os.homedir() at import time.
|
|
7
|
+
vi.mock('os', async (importOriginal) => {
|
|
8
|
+
const original = await importOriginal();
|
|
9
|
+
return { ...original, homedir: () => state.tmpDir };
|
|
10
|
+
});
|
|
11
|
+
import { withNonTestEnv } from './test-utils.js';
|
|
12
|
+
let findLocalCheckoutRoot;
|
|
13
|
+
let resolveLocalCheckout;
|
|
14
|
+
let loadConfig;
|
|
15
|
+
let writeConfig;
|
|
16
|
+
let PRESETS;
|
|
17
|
+
let getCurrentApiUrl;
|
|
18
|
+
/** A fake checkout: `<root>/apps/backender/<file>` for each entry. */
|
|
19
|
+
function makeCheckout(name, files) {
|
|
20
|
+
const root = path.join(state.tmpDir, name);
|
|
21
|
+
const dir = path.join(root, 'apps', 'backender');
|
|
22
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
23
|
+
for (const [file, contents] of Object.entries(files)) {
|
|
24
|
+
fs.writeFileSync(path.join(dir, file), contents);
|
|
25
|
+
}
|
|
26
|
+
return root;
|
|
27
|
+
}
|
|
28
|
+
const WORKTREE_ENV = 'API_BASE_URL=http://localhost:8380\n' +
|
|
29
|
+
'AUTH_URL=http://localhost:3321\n' +
|
|
30
|
+
'CLIENT_APP_URL=http://localhost:3320\n';
|
|
31
|
+
beforeEach(async () => {
|
|
32
|
+
state.tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'tq-local-env-'));
|
|
33
|
+
delete process.env.TQ_BACKEND_URL;
|
|
34
|
+
vi.resetModules();
|
|
35
|
+
({ findLocalCheckoutRoot, resolveLocalCheckout } = await import('./local-env.js'));
|
|
36
|
+
({ loadConfig, writeConfig, PRESETS } = await import('./config.js'));
|
|
37
|
+
({ getCurrentApiUrl } = await import('./token-store.js'));
|
|
38
|
+
});
|
|
39
|
+
afterEach(() => {
|
|
40
|
+
vi.restoreAllMocks();
|
|
41
|
+
delete process.env.TQ_BACKEND_URL;
|
|
42
|
+
fs.rmSync(state.tmpDir, { recursive: true, force: true });
|
|
43
|
+
});
|
|
44
|
+
describe('findLocalCheckoutRoot', () => {
|
|
45
|
+
it('walks up from a subdirectory to the checkout', () => {
|
|
46
|
+
const root = makeCheckout('wt', { '.env': WORKTREE_ENV });
|
|
47
|
+
const sub = path.join(root, 'plugins', 'qinetic-mcp');
|
|
48
|
+
fs.mkdirSync(sub, { recursive: true });
|
|
49
|
+
expect(findLocalCheckoutRoot(sub)).toBe(root);
|
|
50
|
+
});
|
|
51
|
+
it('is undefined outside any checkout', () => {
|
|
52
|
+
const elsewhere = path.join(state.tmpDir, 'some-project');
|
|
53
|
+
fs.mkdirSync(elsewhere, { recursive: true });
|
|
54
|
+
expect(findLocalCheckoutRoot(elsewhere)).toBeUndefined();
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
describe('resolveLocalCheckout', () => {
|
|
58
|
+
it("reads all three URLs from the checkout's backender env", () => {
|
|
59
|
+
const root = makeCheckout('wt', { '.env': WORKTREE_ENV });
|
|
60
|
+
expect(resolveLocalCheckout(root)).toEqual({
|
|
61
|
+
root,
|
|
62
|
+
apiUrl: 'http://localhost:8380',
|
|
63
|
+
authUrl: 'http://localhost:3321',
|
|
64
|
+
clientUrl: 'http://localhost:3320',
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
it('falls back to the local preset when the env names no origin', () => {
|
|
68
|
+
const root = makeCheckout('main', { '.env': 'DB_DATABASE=tqaidb\n' });
|
|
69
|
+
const local = resolveLocalCheckout(root);
|
|
70
|
+
expect(local?.apiUrl).toBe('http://localhost:8080');
|
|
71
|
+
expect(local?.authUrl).toBe('http://localhost:3021');
|
|
72
|
+
expect(local?.clientUrl).toBe('http://localhost:3020');
|
|
73
|
+
});
|
|
74
|
+
it("rejects the SPA's /api proxy URL and uses the preset (internal)", () => {
|
|
75
|
+
const root = makeCheckout('main', {
|
|
76
|
+
'.env': 'API_BASE_URL=https://ai.levr.test:3020/api\n',
|
|
77
|
+
});
|
|
78
|
+
expect(resolveLocalCheckout(root)?.apiUrl).toBe('http://localhost:8080');
|
|
79
|
+
});
|
|
80
|
+
it('lets .env.worktree outrank .env, like the backender', () => {
|
|
81
|
+
const root = makeCheckout('wt', {
|
|
82
|
+
'.env.worktree': 'API_BASE_URL=http://localhost:9180\n',
|
|
83
|
+
'.env': WORKTREE_ENV,
|
|
84
|
+
});
|
|
85
|
+
expect(resolveLocalCheckout(root)?.apiUrl).toBe('http://localhost:9180');
|
|
86
|
+
});
|
|
87
|
+
it('is undefined outside any checkout', () => {
|
|
88
|
+
expect(resolveLocalCheckout(state.tmpDir)).toBeUndefined();
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
// The internal acceptance case: ONE machine-global ~/.tq/config.json, written
|
|
92
|
+
// by `tq:env local` in a worktree, read from two different checkouts.
|
|
93
|
+
describe('one shared `local` config, two checkouts', () => {
|
|
94
|
+
let main;
|
|
95
|
+
let worktree;
|
|
96
|
+
beforeEach(() => {
|
|
97
|
+
main = makeCheckout('main', { '.env': 'DB_DATABASE=tqaidb\n' });
|
|
98
|
+
worktree = makeCheckout('worktree', { '.env': WORKTREE_ENV });
|
|
99
|
+
// What `tq:env local` run in the worktree writes.
|
|
100
|
+
writeConfig({
|
|
101
|
+
environment: 'local',
|
|
102
|
+
apiUrl: 'http://localhost:8380',
|
|
103
|
+
authUrl: 'http://localhost:3321',
|
|
104
|
+
clientUrl: 'http://localhost:3320',
|
|
105
|
+
oauthClientId: '2',
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
const from = (cwd, fn) => {
|
|
109
|
+
vi.spyOn(process, 'cwd').mockReturnValue(cwd);
|
|
110
|
+
return withNonTestEnv(fn);
|
|
111
|
+
};
|
|
112
|
+
it('loadConfig resolves each checkout to its own backend', () => {
|
|
113
|
+
expect(from(main, () => loadConfig()).apiUrl).toBe('http://localhost:8080');
|
|
114
|
+
expect(from(main, () => loadConfig()).authUrl).toBe('http://localhost:3021');
|
|
115
|
+
expect(from(worktree, () => loadConfig()).apiUrl).toBe('http://localhost:8380');
|
|
116
|
+
});
|
|
117
|
+
it('getCurrentApiUrl agrees, so tokens are looked up per checkout', () => {
|
|
118
|
+
expect(from(main, () => getCurrentApiUrl())).toBe('http://localhost:8080');
|
|
119
|
+
expect(from(worktree, () => getCurrentApiUrl())).toBe('http://localhost:8380');
|
|
120
|
+
});
|
|
121
|
+
it('keeps the stored URLs outside any checkout', () => {
|
|
122
|
+
const elsewhere = path.join(state.tmpDir, 'some-project');
|
|
123
|
+
fs.mkdirSync(elsewhere, { recursive: true });
|
|
124
|
+
expect(from(elsewhere, () => loadConfig()).apiUrl).toBe('http://localhost:8380');
|
|
125
|
+
expect(from(elsewhere, () => getCurrentApiUrl())).toBe('http://localhost:8380');
|
|
126
|
+
});
|
|
127
|
+
it('TQ_BACKEND_URL still overrides both', () => {
|
|
128
|
+
process.env.TQ_BACKEND_URL = 'http://localhost:8380';
|
|
129
|
+
expect(from(main, () => loadConfig()).apiUrl).toBe('http://localhost:8380');
|
|
130
|
+
expect(from(main, () => getCurrentApiUrl())).toBe('http://localhost:8380');
|
|
131
|
+
});
|
|
132
|
+
it('staging stays global: every checkout follows it', () => {
|
|
133
|
+
writeConfig(PRESETS.staging);
|
|
134
|
+
expect(from(main, () => loadConfig()).apiUrl).toBe('https://api.levr.now');
|
|
135
|
+
expect(from(worktree, () => getCurrentApiUrl())).toBe('https://api.levr.now');
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
//# sourceMappingURL=local-env.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local-env.test.js","sourceRoot":"","sources":["../src/local-env.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACzE,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AAEzB,MAAM,KAAK,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;AAEjD,oEAAoE;AACpE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,cAAc,EAAE,EAAE;IACrC,MAAM,QAAQ,GAAG,MAAM,cAAc,EAAuB,CAAC;IAC7D,OAAO,EAAE,GAAG,QAAQ,EAA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;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAsB5D;AAED,oEAAoE;AACpE,MAAM,WAAW,YAAY;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,OAAO,GAAG,YAAY,GAAG,SAAS,CAsBvE"}
|
package/dist/status-report.js
CHANGED
|
@@ -95,7 +95,12 @@ export function buildTokenRows(entries, activeUrl, now) {
|
|
|
95
95
|
* `PRESETS` is what keeps this copy honest.
|
|
96
96
|
*/
|
|
97
97
|
export function backendUrlForLevrMcp(levrUrl) {
|
|
98
|
-
|
|
98
|
+
// internal: a scoped or levr-browser URL — `…/v1/mcp/w/<url_key>`,
|
|
99
|
+
// `…/v1/mcp/browser`, `…/v1/mcp/browser/w/<url_key>` — is the same backend
|
|
100
|
+
// as its `…/v1/mcp` (`unscopedLevrMcpUrl` is the scripts/ twin).
|
|
101
|
+
const base = levrUrl
|
|
102
|
+
.replace(/\/+$/, '')
|
|
103
|
+
.replace(/\/v1\/mcp(?:\/browser)?(?:\/w\/[^/]+)?$/, '');
|
|
99
104
|
// ONLY the two hosted presets. `PRESETS.local` must never join this list:
|
|
100
105
|
// under DEV_TLS it is `LOCAL_HTTPS`, whose clientUrl+`/api` is
|
|
101
106
|
// `https://ai.levr.test:3020/api` — a real key in the token map that has to
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"status-report.js","sourceRoot":"","sources":["../src/status-report.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAatC,MAAM,UAAU,YAAY,CAAC,SAAiB,EAAE,GAAW;IACzD,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAA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
import { PRESETS } from './config.js';
|
|
3
|
+
import { normalizeBackendUrl } from './token-store.js';
|
|
3
4
|
import { backendUrlForLevrMcp, buildTokenRows, formatExpiry, labelForBackend, levrEntryFrom, } from './status-report.js';
|
|
4
5
|
const NOW = 1_700_000_000_000;
|
|
5
6
|
const at = (minutes) => ({ expiresAt: NOW + minutes * 60_000 });
|
|
@@ -115,6 +116,33 @@ describe('backendUrlForLevrMcp', () => {
|
|
|
115
116
|
it('tolerates a trailing slash', () => {
|
|
116
117
|
expect(backendUrlForLevrMcp('https://ai.levr.now/api/v1/mcp/')).toBe('https://api.levr.now');
|
|
117
118
|
});
|
|
119
|
+
// internal: a scoped (internal) or levr-browser (internal) URL is the same
|
|
120
|
+
// backend as its /v1/mcp.
|
|
121
|
+
it.each([
|
|
122
|
+
'https://ai.levr.now/api/v1/mcp',
|
|
123
|
+
'https://ai.levr.now/api/v1/mcp/w/bitmodern5',
|
|
124
|
+
'https://ai.levr.now/api/v1/mcp/w/bitmodern5/',
|
|
125
|
+
'https://ai.levr.now/api/v1/mcp/browser',
|
|
126
|
+
'https://ai.levr.now/api/v1/mcp/browser/w/bitmodern5',
|
|
127
|
+
])('maps %s to the staging api host', (url) => {
|
|
128
|
+
expect(backendUrlForLevrMcp(url)).toBe(PRESETS.staging.apiUrl);
|
|
129
|
+
});
|
|
130
|
+
it('keys a scoped worktree local like its unscoped url', () => {
|
|
131
|
+
expect(backendUrlForLevrMcp('http://localhost:9780/v1/mcp/w/acme/')).toBe('http://localhost:9780');
|
|
132
|
+
expect(backendUrlForLevrMcp('https://ai.levr.test:3020/api/v1/mcp/browser/w/acme')).toBe('https://ai.levr.test:3020/api');
|
|
133
|
+
});
|
|
134
|
+
it('tq:status: a scoped URL on the configured host is NOT a different backend', () => {
|
|
135
|
+
// The exact predicate `tq:status` (cli.ts) warns on.
|
|
136
|
+
const active = normalizeBackendUrl(PRESETS.staging.apiUrl);
|
|
137
|
+
for (const url of [
|
|
138
|
+
'https://ai.levr.now/api/v1/mcp/w/bitmodern5',
|
|
139
|
+
'https://ai.levr.now/api/v1/mcp/w/bitmodern5/',
|
|
140
|
+
]) {
|
|
141
|
+
expect(normalizeBackendUrl(backendUrlForLevrMcp(url))).toBe(active);
|
|
142
|
+
}
|
|
143
|
+
// Positive control: another host still disagrees.
|
|
144
|
+
expect(normalizeBackendUrl(backendUrlForLevrMcp('https://ai.levr.one/api/v1/mcp/w/bitmodern5'))).not.toBe(active);
|
|
145
|
+
});
|
|
118
146
|
});
|
|
119
147
|
describe('levrEntryFrom', () => {
|
|
120
148
|
const config = {
|