@synopackageland/cli 0.48.18 → 0.48.20
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/CHANGELOG.md +14 -0
- package/dist/e2e/dsm.d.ts +5 -3
- package/dist/e2e/dsm.js +29 -10
- package/dist/init.js +2 -1
- package/dist/skill.js +1 -0
- package/package.json +1 -1
- package/skills/SKILL.md +25 -1
- package/skills/reference/files.md +37 -0
- package/skills/reference/testing.md +134 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.48.20
|
|
4
|
+
|
|
5
|
+
- Add optional App testing guidance, from fast local unit and ctl registry contracts through local package checks, real-NAS ctl, deterministic UI tests and optional AI steps
|
|
6
|
+
- Include shared test and support files during project initialization while preserving existing files and the App-open smoke
|
|
7
|
+
- Require an explicit AI model profile and default reasoning effort to low; missing settings report the required environment variables instead of selecting a provider silently
|
|
8
|
+
|
|
9
|
+
### Upgrading
|
|
10
|
+
|
|
11
|
+
AI steps using `magpieAgent()` or `e2eAgent()` now require `E2E_LLM_BASE_URL`, `E2E_LLM_MODEL` and either `E2E_LLM_API_KEY` or `E2E_LLM_API_KEY_FILE` (a private mode-600 key file). Set them in the test process environment or an untracked environment file before running AI steps. `E2E_LLM_REASONING_EFFORT` is optional and defaults to `low`. No endpoint, model or key is supplied automatically; non-AI tests need no AI profile.
|
|
12
|
+
|
|
13
|
+
## 0.48.19
|
|
14
|
+
|
|
15
|
+
- Skill documents multi-user Apps: administrator scope confirmation first, each user's home as the default destination root with relative subfolders created as that user, and a `SYNO.Core.User.Home` check with a reminder when user home is off
|
|
16
|
+
|
|
3
17
|
## 0.48.18
|
|
4
18
|
|
|
5
19
|
- Skill documents HTTP/HTTPS handling: HTTP stays allowed with no automatic redirect, `identity_gateway.secure_context: required` for Apps that need a secure context, and upstream OIDC callbacks that follow the request scheme instead of a hard-coded https
|
package/dist/e2e/dsm.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type AppOpenSmokeOptions, type SmokeMarker } from "./app-open.js";
|
|
2
|
-
export { deriveSmokeEntry, type AppOpenSmokeOptions, type SmokeMarker } from "./app-open.js";
|
|
2
|
+
export { deriveSmokeEntry, readSmokeEntry, type AppOpenSmokeOptions, type SmokeMarker } from "./app-open.js";
|
|
3
3
|
import { surfaceOf } from "@e2e-dev/web";
|
|
4
4
|
type Env = Readonly<Record<string, string | undefined>>;
|
|
5
5
|
type App = {
|
|
@@ -42,7 +42,7 @@ export declare function redactDsmSecrets(text: string): string;
|
|
|
42
42
|
* a saved session must restore the real cookies. Does nothing when `dir` is missing.
|
|
43
43
|
*/
|
|
44
44
|
export declare function protectE2eOutput(dir: string): void;
|
|
45
|
-
/**
|
|
45
|
+
/** AI is opt-in: no endpoint, credential or model is selected for the caller. */
|
|
46
46
|
export declare function llmSettings(env?: Env): {
|
|
47
47
|
baseURL: string;
|
|
48
48
|
model: string;
|
|
@@ -50,7 +50,7 @@ export declare function llmSettings(env?: Env): {
|
|
|
50
50
|
reasoningEffort: string;
|
|
51
51
|
};
|
|
52
52
|
/** The `agents.default` entry of e2e.config.ts: model plus the effort sent with every request. */
|
|
53
|
-
export declare function
|
|
53
|
+
export declare function e2eAgent(env?: Env): {
|
|
54
54
|
model: import("@ai-sdk/provider").LanguageModelV4;
|
|
55
55
|
providerOptions: {
|
|
56
56
|
openai: {
|
|
@@ -58,6 +58,8 @@ export declare function magpieAgent(env?: Env): {
|
|
|
58
58
|
};
|
|
59
59
|
};
|
|
60
60
|
};
|
|
61
|
+
/** Backwards-compatible name; uses only the caller's E2E_LLM_* configuration. */
|
|
62
|
+
export declare const magpieAgent: typeof e2eAgent;
|
|
61
63
|
/**
|
|
62
64
|
* Reads one account from a private JSON file: `{username, password}` or
|
|
63
65
|
* `{users: {<user>: {username, password}}}`. Errors never include the values.
|
package/dist/e2e/dsm.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// It signs in once per run (a saved, private profile is restored when still valid),
|
|
4
4
|
// opens DSM app windows and Application Portal pages (accepting their native
|
|
5
5
|
// dialogs when given the `browser` fixture), dismisses DSM notifications,
|
|
6
|
-
// configures
|
|
6
|
+
// configures an optional user-selected LLM, and runs a command through an SSH tunnel to the NAS
|
|
7
7
|
// (on a free loopback port unless DSM_E2E_TUNNEL_PORT names one). DSM's session
|
|
8
8
|
// cookies and tokens are masked in what that command prints and leaves in its
|
|
9
9
|
// e2e output, which is made private (directories 700, files 600).
|
|
@@ -21,7 +21,7 @@ import { dirname, join, resolve } from "node:path";
|
|
|
21
21
|
import { fileURLToPath } from "node:url";
|
|
22
22
|
import { createRequire } from "node:module";
|
|
23
23
|
import { readSmokeEntry } from "./app-open.js";
|
|
24
|
-
export { deriveSmokeEntry } from "./app-open.js";
|
|
24
|
+
export { deriveSmokeEntry, readSmokeEntry } from "./app-open.js";
|
|
25
25
|
import { surfaceOf, test, web } from "@e2e-dev/web";
|
|
26
26
|
import { withDsmCertificates } from "./certificates.js";
|
|
27
27
|
const safeName = /^[A-Za-z0-9][A-Za-z0-9_.-]{0,63}$/;
|
|
@@ -232,17 +232,35 @@ function redactFile(file) {
|
|
|
232
232
|
writeFileSync(file, masked, { mode: 0o600 });
|
|
233
233
|
}
|
|
234
234
|
// ---- LLM ------------------------------------------------------------------
|
|
235
|
-
/**
|
|
235
|
+
/** AI is opt-in: no endpoint, credential or model is selected for the caller. */
|
|
236
236
|
export function llmSettings(env = process.env) {
|
|
237
|
+
const baseURL = env.E2E_LLM_BASE_URL?.trim();
|
|
238
|
+
const model = env.E2E_LLM_MODEL?.trim();
|
|
239
|
+
let apiKey = env.E2E_LLM_API_KEY?.trim();
|
|
240
|
+
const missing = [
|
|
241
|
+
...(!baseURL ? ['E2E_LLM_BASE_URL'] : []),
|
|
242
|
+
...(!model ? ['E2E_LLM_MODEL'] : []),
|
|
243
|
+
...(!apiKey && !env.E2E_LLM_API_KEY_FILE?.trim() ? ['E2E_LLM_API_KEY or E2E_LLM_API_KEY_FILE'] : []),
|
|
244
|
+
];
|
|
245
|
+
if (missing.length) {
|
|
246
|
+
throw new Error(`AI e2e configuration is missing: ${missing.join(', ')}. Set these variables before calling e2eAgent() or magpieAgent(); there is no default endpoint, model or key. Non-AI tests do not need a model profile.`);
|
|
247
|
+
}
|
|
248
|
+
if (!apiKey && env.E2E_LLM_API_KEY_FILE) {
|
|
249
|
+
requirePrivate(env.E2E_LLM_API_KEY_FILE, 'AI key file');
|
|
250
|
+
apiKey = readFileSync(env.E2E_LLM_API_KEY_FILE, 'utf8').trim();
|
|
251
|
+
}
|
|
252
|
+
if (!apiKey)
|
|
253
|
+
throw new Error('AI e2e requires E2E_LLM_API_KEY or E2E_LLM_API_KEY_FILE; configure a model profile or use the non-AI tests.');
|
|
237
254
|
return {
|
|
238
|
-
baseURL:
|
|
239
|
-
model:
|
|
240
|
-
apiKey
|
|
241
|
-
reasoningEffort: env.E2E_LLM_REASONING_EFFORT ||
|
|
255
|
+
baseURL: baseURL,
|
|
256
|
+
model: model,
|
|
257
|
+
apiKey,
|
|
258
|
+
reasoningEffort: env.E2E_LLM_REASONING_EFFORT || 'low',
|
|
242
259
|
};
|
|
243
260
|
}
|
|
244
261
|
/** The `agents.default` entry of e2e.config.ts: model plus the effort sent with every request. */
|
|
245
|
-
export function
|
|
262
|
+
export function e2eAgent(env = process.env) {
|
|
263
|
+
const settings = llmSettings(env);
|
|
246
264
|
// Keep the synchronous config API; load the optional ESM provider only when
|
|
247
265
|
// an agent is requested (Node 22.12+ supports require(esm)). Smoke tests do
|
|
248
266
|
// not need the AI SDK or any model provider installed.
|
|
@@ -253,14 +271,15 @@ export function magpieAgent(env = process.env) {
|
|
|
253
271
|
catch (error) {
|
|
254
272
|
if (!['MODULE_NOT_FOUND', 'ERR_MODULE_NOT_FOUND'].includes(error.code ?? ''))
|
|
255
273
|
throw error;
|
|
256
|
-
throw new Error('
|
|
274
|
+
throw new Error('e2eAgent requires optional @ai-sdk/openai and ai; install them to run AI agents.', { cause: error });
|
|
257
275
|
}
|
|
258
|
-
const settings = llmSettings(env);
|
|
259
276
|
return {
|
|
260
277
|
model: provider.createOpenAI({ baseURL: settings.baseURL, apiKey: settings.apiKey }).chat(settings.model),
|
|
261
278
|
providerOptions: { openai: { reasoningEffort: settings.reasoningEffort } },
|
|
262
279
|
};
|
|
263
280
|
}
|
|
281
|
+
/** Backwards-compatible name; uses only the caller's E2E_LLM_* configuration. */
|
|
282
|
+
export const magpieAgent = e2eAgent;
|
|
264
283
|
// ---- Accounts and profiles ------------------------------------------------
|
|
265
284
|
function requirePrivate(file, what) {
|
|
266
285
|
if (statSync(file).mode & 0o077)
|
package/dist/init.js
CHANGED
|
@@ -207,7 +207,8 @@ export function initFromTemplate(template, targetDir, options = {}) {
|
|
|
207
207
|
"AGENTS.md",
|
|
208
208
|
"CLAUDE.md",
|
|
209
209
|
...sharedScripts,
|
|
210
|
-
...["package.json", "e2e.config.ts", "
|
|
210
|
+
...["package.json", "e2e.config.ts", "e2e.ai.config.ts"].filter(file => existsSync(join(shared, file))),
|
|
211
|
+
...["tests", "scripts"].flatMap(dir => existsSync(join(shared, dir)) ? templateFiles(join(shared, dir)).map(file => `${dir}/${file}`) : []),
|
|
211
212
|
];
|
|
212
213
|
const files = [
|
|
213
214
|
...templateFiles(source),
|
package/dist/skill.js
CHANGED
|
@@ -5,6 +5,7 @@ const SKILL_CATALOG = [
|
|
|
5
5
|
{ id: "orchestrator", file: "SKILL.md", when: "Read first" },
|
|
6
6
|
{ id: "host-install", file: "reference/host-install.md", when: "Shared NAS login, store/local SPK installation and removal" },
|
|
7
7
|
{ id: "ctl", file: "reference/ctl.md", when: "Operate registered NAS Apps or design AI commands" },
|
|
8
|
+
{ id: "testing", file: "reference/testing.md", when: "Choose optional local, NAS ctl, UI or AI tests" },
|
|
8
9
|
{
|
|
9
10
|
id: "create",
|
|
10
11
|
file: "reference/create.md",
|
package/package.json
CHANGED
package/skills/SKILL.md
CHANGED
|
@@ -296,6 +296,15 @@ sweep forward the cancel instead of admitting it.
|
|
|
296
296
|
- Wizard support is measured on the test NAS DSM 7.4 via a session-only SSH local
|
|
297
297
|
forward. This is not proof of other DSM releases or full writer/reboot behavior.
|
|
298
298
|
|
|
299
|
+
### Multi-user Apps
|
|
300
|
+
|
|
301
|
+
Multi-user Apps: the administrator confirms the install scope first; each user's
|
|
302
|
+
destination root defaults to their own home with a relative subfolder chosen on
|
|
303
|
+
first use (created by the executor as that user); check the home service with
|
|
304
|
+
`SYNO.Core.User.Home` `get` before relying on it, and when it is off, remind the
|
|
305
|
+
user (administrators get a Control Panel shortcut) instead of enabling it. Read
|
|
306
|
+
`reference/files.md` "Multi-user Apps: home as the default destination root".
|
|
307
|
+
|
|
299
308
|
## 開啟方式
|
|
300
309
|
|
|
301
310
|
原生 App 在 `dsm-package.yaml` 設定 `ui.launch: dsm-window | new-page`。
|
|
@@ -338,6 +347,21 @@ readiness 不跟隨 redirect,check 不會發 HTTP。Compose 不支援 ctl。
|
|
|
338
347
|
|
|
339
348
|
For controlling installed Apps or designing task-level AI commands, read [reference/ctl.md](reference/ctl.md). Declare operations once in a synopkgland.api v2 registry with a required ai class; run `ctl generate`, `ctl generate --check` and `check`. Operation descriptions belong only in that registry; read the generated per-App reference. Import OSS APIs hidden and obtain explicit per-API opt-in grouped by area before exposing them. Use ctl host list, register/renew explicitly, discover all commands, and always name the host when agents may operate multiple NAS machines.
|
|
340
349
|
|
|
350
|
+
## Optional basic testing
|
|
351
|
+
|
|
352
|
+
Scaffold the basic test files by default. Ask once whether the user wants no
|
|
353
|
+
tests, local/non-AI tests, or optional AI steps too; respect the answer for the
|
|
354
|
+
task. Writing and running tests are optional. Accept no tests, do not nag, and
|
|
355
|
+
never block a build or release on tests. The default local loop uses only fast
|
|
356
|
+
unit/ctl registry contracts; the full suite is slow. Real-NAS ctl, App-open smoke,
|
|
357
|
+
UI e2e and AI e2e run only when the user explicitly asks.
|
|
358
|
+
|
|
359
|
+
Read [reference/testing.md](reference/testing.md) when creating or extending tests
|
|
360
|
+
for tier commands, meaningful ctl/UI assertions and bounded job lifecycle tests.
|
|
361
|
+
Non-AI tiers need no AI key. AI steps need a configured endpoint, key location
|
|
362
|
+
and model; if setup is unknown, ask the user for those values. Choose the cheapest
|
|
363
|
+
adequate model with low effort, never an expensive default.
|
|
364
|
+
|
|
341
365
|
## App-open smoke
|
|
342
366
|
|
|
343
367
|
Every generated project has `tests/e2e/smoke.e2e.ts` and `npm run e2e:smoke`.
|
|
@@ -347,7 +371,7 @@ reuses the existing DSM credentials/profiles/tunnel, and registers administrator
|
|
|
347
371
|
normal-user and fresh anonymous tests. Configure `DSM_E2E_ACCOUNT_ADMIN` and
|
|
348
372
|
`DSM_E2E_ACCOUNT_NORMAL` as private account files; a missing normal profile and
|
|
349
373
|
credentials is a reported skip. Smoke needs `e2e`, `@e2e-dev/web` and Chromium;
|
|
350
|
-
`ai` and `@ai-sdk/openai` are required only for
|
|
374
|
+
`ai` and `@ai-sdk/openai` are optional installs required only for AI steps. Declare an optional
|
|
351
375
|
interstitial as `preReady: {clickIfVisible: {text: "Continue on this device"}}`.
|
|
352
376
|
For `entry: admin-only`, N must see the SDK gateway denial page or an explicit
|
|
353
377
|
DSM denial/launcher privilege signal without an App window. Timeout alone is not
|
|
@@ -132,6 +132,43 @@ sweep forward the cancel instead of admitting it.
|
|
|
132
132
|
|
|
133
133
|
The pinned scope-selection task also binds the protected generation observed before confirmation. The executor compares it under the publish lock and refuses stale tasks, so a retained task cannot replay an older selection after another confirmation.
|
|
134
134
|
|
|
135
|
+
### Multi-user Apps: home as the default destination root
|
|
136
|
+
|
|
137
|
+
When several DSM users use the same App, follow this order:
|
|
138
|
+
|
|
139
|
+
1. **Administrator first.** The administrator enables the delegate and confirms
|
|
140
|
+
the install-selected scope (shares and/or home) with the existing
|
|
141
|
+
PasswordConfirm form. Nothing user-facing writes files before that.
|
|
142
|
+
2. **Home by default.** Each user's destination root defaults to their own home
|
|
143
|
+
(File Station `/home`), not a shared folder that every user must be granted.
|
|
144
|
+
With an active scope that includes home, the backend can call
|
|
145
|
+
`Service.Destination` / `SelectDestination` for `/home` non-interactively on
|
|
146
|
+
the user's fresh DSM session; the executor still verifies session, UID and
|
|
147
|
+
write access. Shares remain an explicit per-user choice in the picker.
|
|
148
|
+
3. **Subfolder under the root.** Treat the destination as a root. On first use,
|
|
149
|
+
show a short confirmation with a suggested relative subfolder (an App-specific
|
|
150
|
+
name) the user can edit; later features (per-rule or per-item folders) use
|
|
151
|
+
further relative paths under the same root. Pass them as the nested
|
|
152
|
+
relative `Name` of `files.moveFromStaging` (for example `Folder/Sub/file.ext`).
|
|
153
|
+
The executor creates missing folders as the user, with the user's owner and
|
|
154
|
+
inherited ACL, never crossing symlinks or mounts. Do not create folders from
|
|
155
|
+
the App identity or as root, and never store absolute `/volumeN/...` paths.
|
|
156
|
+
4. **Check the home service before relying on it.** User home can be disabled
|
|
157
|
+
in Control Panel. Query `SYNO.Core.User.Home` `get` (version 1) with an
|
|
158
|
+
administrator session; `data.enable` is the local home switch
|
|
159
|
+
(`enable_domain` / `enable_ldap` cover directory users). Run the check in the
|
|
160
|
+
background and do not block the page. For a non-administrator, treat a
|
|
161
|
+
refused `/home` selection (no home in the user's own share view) as "home is
|
|
162
|
+
off".
|
|
163
|
+
5. **Home off: remind, never enable.** Do not enable the home service
|
|
164
|
+
automatically. Administrators get the reason, a button that opens Control
|
|
165
|
+
Panel > User & Group > Advanced, and Retry. Other users see that the
|
|
166
|
+
administrator must enable user home, and may pick another allowed folder
|
|
167
|
+
in the meantime. Re-check on Retry and on next start.
|
|
168
|
+
|
|
169
|
+
Each user only sees and writes folders their own DSM account can write; the App
|
|
170
|
+
never widens access, and files from different users never share a grant.
|
|
171
|
+
|
|
135
172
|
## Container mounts
|
|
136
173
|
|
|
137
174
|
Containers use a fixed package identity and never inherit the signed-in user's File Station ACL. Mount grants are distinct from user destination grants. Per-user file access requires a session/Broker Adapter, outside this change. Read [compose.md](compose.md); official ACL/project control remains blocked.
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
# Optional basic App tests
|
|
2
|
+
|
|
3
|
+
Include the scaffold by default; ask once whether the user wants no tests,
|
|
4
|
+
local/non-AI tests, or optional AI steps as well. Honor the choice throughout the
|
|
5
|
+
task. Declining tests is fine: skip writing and running them, do not nag, and
|
|
6
|
+
never block a build or release on tests. The full suite is slow; do not run it
|
|
7
|
+
after every change. Nothing runs on a NAS automatically.
|
|
8
|
+
|
|
9
|
+
## Tiers, cheapest first
|
|
10
|
+
|
|
11
|
+
| Tier | Explicit command | Minimal useful assertion |
|
|
12
|
+
| --- | --- | --- |
|
|
13
|
+
| Local unit / ctl registry | `npm test` or `npm run test:unit` | Pin an operation's CLI path, read/write effect and handler; unit-test business results |
|
|
14
|
+
| Local package | `npm run test:local` | Check, build one architecture, inspect each emitted SPK |
|
|
15
|
+
| Real-NAS ctl | `npm run test:nas:ctl` | Use actual `synopkgland ctl` commands and assert package ID, caller role and nonroot UID |
|
|
16
|
+
| Real-NAS UI, no AI | `npm run e2e:ui` | Use selectors, perform the primary action and assert its changed saved/read-back result |
|
|
17
|
+
| Optional AI UI step | `npm run e2e:ai` | One bounded `agent.act` followed by the same deterministic result assertion |
|
|
18
|
+
|
|
19
|
+
After the user opts into tests, the default development loop runs only the first
|
|
20
|
+
tier relevant to the change. The local package tier is a separate, explicit
|
|
21
|
+
check. Every NAS tier, including `npm run e2e:smoke`, needs an explicit user
|
|
22
|
+
request and authorized fixtures. Keep build/release and lifecycle hooks independent
|
|
23
|
+
of tests. Test failures are evidence to report, not an automatic release veto.
|
|
24
|
+
|
|
25
|
+
`init` includes examples under `tests/unit`, `tests/local`, `tests/ctl` and
|
|
26
|
+
`tests/e2e`, plus independent npm scripts. Adapt examples when replacing the
|
|
27
|
+
starter status operation; an empty upstream registry has no starter contract to
|
|
28
|
+
test. Do not add ctl to a wrapper merely to enable the example. Existing
|
|
29
|
+
backend-language unit tests remain useful when the user chooses them.
|
|
30
|
+
|
|
31
|
+
## Real-NAS ctl through the CLI
|
|
32
|
+
|
|
33
|
+
Discover the installed App's commands with `synopkgland ctl list --host <profile>
|
|
34
|
+
--app <package> --json`, completing approval only within the user's authorization.
|
|
35
|
+
Use the registered CLI host/session, not raw HTTP or a mocked transport. Configure
|
|
36
|
+
`APP_TEST_HOST` and optionally `APP_TEST_APP` (package ID/known alias) and
|
|
37
|
+
`APP_TEST_CTL_COMMAND` (a JSON argv array from discovery). The starter example
|
|
38
|
+
uses `app status`, then asserts concrete `package`, `admin` and `process.uid`
|
|
39
|
+
values. Replace these assertions with your App's real contract.
|
|
40
|
+
|
|
41
|
+
For a write, create only an authorized private fixture, read it back through ctl,
|
|
42
|
+
assert its ID and exact changed fields, then clean up. A successful exit or valid
|
|
43
|
+
JSON schema alone does not establish the intended result. Do not replay an
|
|
44
|
+
uncertain write; query its original ID first.
|
|
45
|
+
|
|
46
|
+
## UI without AI
|
|
47
|
+
|
|
48
|
+
Keep the separate App-open smoke for administrator, normal-user and anonymous
|
|
49
|
+
entry policy. Rendering alone does not test the main feature.
|
|
50
|
+
|
|
51
|
+
The action example uses `APP_TEST_ACTION` (a CSS selector), `APP_TEST_RESULT`
|
|
52
|
+
(a result selector) and `APP_TEST_EXPECTED` (exact resulting text). Prepare an
|
|
53
|
+
authorized fixture whose initial value differs from the expected result. Fill
|
|
54
|
+
required fields before clicking, then assert the saved/read-back outcome: for
|
|
55
|
+
example, rename a fixture and verify its new name after reload, or enqueue a job
|
|
56
|
+
and verify its ID in the list. Replace generic selectors/assertions with stable
|
|
57
|
+
App-specific ones. The example follows the manifest's window/page launcher;
|
|
58
|
+
`APP_TEST_ENTRY` optionally selects a configured entry path.
|
|
59
|
+
|
|
60
|
+
Reuse `DSM_E2E_ACCOUNT_ADMIN` / `DSM_E2E_ACCOUNT_NORMAL` private account files,
|
|
61
|
+
saved profiles and the existing tunnel. Read [host-install.md](host-install.md)
|
|
62
|
+
for CLI sessions. Keep `.env` and `.e2e/` untracked; no test installs or deploys
|
|
63
|
+
an App on its own. Non-AI config imports no model provider and needs no AI key.
|
|
64
|
+
|
|
65
|
+
## Long-running jobs: test the lifecycle, never full completion
|
|
66
|
+
|
|
67
|
+
Use a deliberately long, private fixture and adapt the following helper's
|
|
68
|
+
callbacks and state/progress fields to the actual App registry. Each callback
|
|
69
|
+
must have its own request timeout; ctl callbacks execute the discovered CLI
|
|
70
|
+
commands. UI tests drive the same controls and observe the same job ID.
|
|
71
|
+
|
|
72
|
+
```js
|
|
73
|
+
import assert from 'node:assert/strict';
|
|
74
|
+
import {setTimeout as delay} from 'node:timers/promises';
|
|
75
|
+
|
|
76
|
+
async function until(get, predicate) {
|
|
77
|
+
const deadline = Date.now() + 10_000;
|
|
78
|
+
do {
|
|
79
|
+
const value = await get();
|
|
80
|
+
if (predicate(value)) return value;
|
|
81
|
+
assert.ok(!['completed', 'failed'].includes(value.state));
|
|
82
|
+
await delay(100);
|
|
83
|
+
} while (Date.now() < deadline);
|
|
84
|
+
throw new Error('Job lifecycle observation timed out');
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
async function lifecycle(api, fixture) {
|
|
88
|
+
const job = await api.start(fixture);
|
|
89
|
+
try {
|
|
90
|
+
const progressed = await until(() => api.get(job.id), j => j.progress > 0);
|
|
91
|
+
assert.equal(progressed.id, job.id);
|
|
92
|
+
await api.pause(job.id);
|
|
93
|
+
const paused = await until(() => api.get(job.id), j => j.state === 'paused');
|
|
94
|
+
assert.ok(paused.progress >= progressed.progress);
|
|
95
|
+
const resuming = await api.resume(job.id); // adapter returns the retained snapshot
|
|
96
|
+
assert.equal(resuming.id, job.id);
|
|
97
|
+
assert.ok(resuming.progress >= paused.progress);
|
|
98
|
+
const resumed = await until(() => api.get(job.id), j =>
|
|
99
|
+
j.state === 'running' && j.progress >= paused.progress);
|
|
100
|
+
assert.equal(resumed.id, job.id);
|
|
101
|
+
assert.ok(resumed.progress >= paused.progress); // no reset on resume
|
|
102
|
+
// Prefer a retained checkpoint/byte offset too, when the App exposes one.
|
|
103
|
+
} finally {
|
|
104
|
+
await api.cancel(job.id);
|
|
105
|
+
const cancelled = await until(() => api.get(job.id), j => j.state === 'cancelled');
|
|
106
|
+
assert.equal(cancelled.id, job.id);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Assert retained checkpoint/progress on resume; do not accept a new job ID or a
|
|
112
|
+
reset. Cancel even when an assertion fails and clean up only the test fixture.
|
|
113
|
+
Never wait for the entire workload to finish. If the App cannot pause/resume,
|
|
114
|
+
report that unsupported lifecycle step rather than inventing a command.
|
|
115
|
+
|
|
116
|
+
## Optional AI profile
|
|
117
|
+
|
|
118
|
+
Offer only non-AI tiers when the user wants no AI. If they request AI, install
|
|
119
|
+
`ai` and `@ai-sdk/openai` explicitly; the normal scaffold does not need them.
|
|
120
|
+
`e2e.ai.config.ts` is loaded only by `e2e:ai`. `e2eAgent()` reads:
|
|
121
|
+
|
|
122
|
+
- `E2E_LLM_BASE_URL`: the user's OpenAI-compatible endpoint
|
|
123
|
+
- `E2E_LLM_MODEL`: the cheapest model adequate for this bounded action
|
|
124
|
+
- `E2E_LLM_API_KEY_FILE`: a private mode-600 file containing the key, or
|
|
125
|
+
`E2E_LLM_API_KEY` supplied through the environment
|
|
126
|
+
- `E2E_LLM_REASONING_EFFORT`: defaults to `low`
|
|
127
|
+
|
|
128
|
+
There is no built-in endpoint, key or model. The legacy `magpieAgent` export is
|
|
129
|
+
an alias with the same explicit configuration. Never select an expensive model
|
|
130
|
+
by default. If no profile exists and you do not know the user's setup, ask for
|
|
131
|
+
the endpoint, key location and model. Do not print keys or put them in argv.
|
|
132
|
+
|
|
133
|
+
Set `APP_TEST_AI_ACTION` to one authorized fixture action. Keep a deterministic
|
|
134
|
+
selector/result assertion after `agent.act`; an AI assertion alone is insufficient.
|