@synopackageland/cli 0.48.19 → 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 CHANGED
@@ -1,5 +1,15 @@
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
+
3
13
  ## 0.48.19
4
14
 
5
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
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
- /** magpie's GPT-6 Luna at max reasoning effort unless E2E_LLM_* says otherwise. */
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 magpieAgent(env?: Env): {
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 the magpie LLM, and runs a command through an SSH tunnel to the NAS
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
- /** magpie's GPT-6 Luna at max reasoning effort unless E2E_LLM_* says otherwise. */
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: env.E2E_LLM_BASE_URL || "http://127.0.0.1:3425/v1",
239
- model: env.E2E_LLM_MODEL || "codex/gpt-6-luna",
240
- apiKey: env.E2E_LLM_API_KEY || "magpie-local",
241
- reasoningEffort: env.E2E_LLM_REASONING_EFFORT || "max",
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 magpieAgent(env = process.env) {
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('magpieAgent requires optional @ai-sdk/openai and ai; install them to run AI agents.', { cause: 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", "tests/e2e/smoke.e2e.ts"].filter(file => existsSync(join(shared, file))),
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@synopackageland/cli",
3
- "version": "0.48.19",
3
+ "version": "0.48.20",
4
4
  "description": "Syno Package Land Developer Kit CLI",
5
5
  "type": "module",
6
6
  "bin": {
package/skills/SKILL.md CHANGED
@@ -347,6 +347,21 @@ readiness 不跟隨 redirect,check 不會發 HTTP。Compose 不支援 ctl。
347
347
 
348
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.
349
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
+
350
365
  ## App-open smoke
351
366
 
352
367
  Every generated project has `tests/e2e/smoke.e2e.ts` and `npm run e2e:smoke`.
@@ -356,7 +371,7 @@ reuses the existing DSM credentials/profiles/tunnel, and registers administrator
356
371
  normal-user and fresh anonymous tests. Configure `DSM_E2E_ACCOUNT_ADMIN` and
357
372
  `DSM_E2E_ACCOUNT_NORMAL` as private account files; a missing normal profile and
358
373
  credentials is a reported skip. Smoke needs `e2e`, `@e2e-dev/web` and Chromium;
359
- `ai` and `@ai-sdk/openai` are required only for `magpieAgent()`. Declare an optional
374
+ `ai` and `@ai-sdk/openai` are optional installs required only for AI steps. Declare an optional
360
375
  interstitial as `preReady: {clickIfVisible: {text: "Continue on this device"}}`.
361
376
  For `entry: admin-only`, N must see the SDK gateway denial page or an explicit
362
377
  DSM denial/launcher privilege signal without an App window. Timeout alone is not
@@ -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.