@synopackageland/templates 0.26.5 → 0.27.1

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
@@ -22,8 +22,8 @@ daemon:
22
22
  window_seconds: 300
23
23
  ```
24
24
 
25
- Templates 0.26.5 pin SDK 0.27.0 in native and Compose projects.
26
- Daemon restart declarations need CLI 0.26.0 or later. Go Apps select
25
+ Templates 0.27.0 inherit UI 0.14.9 from 0.26.5 and pin SDK 0.27.0 in native and Compose projects.
26
+ Use CLI 0.27.0 or later. Go Apps select
27
27
  their controller from their Go SDK requirement; an identity gateway selects it
28
28
  from `identity_gateway.sdk`. The CLI rejects older selected versions, even for
29
29
  an explicit `mode: off`, rather than dropping the declaration. A local SDK source
@@ -49,7 +49,7 @@ identity gateway and keeps its own settings in an administrator-only DSM window.
49
49
  | --- | --- |
50
50
  | `native-go` | Base: `dsm-package.yaml`, Go module (`backend/cmd/{app,background-worker}`, `backend/internal/app`, `backend/internal/api/permissions.json`), plain `ui/`, i18n |
51
51
  | `native-go-vue` | Vue shell in `frontend/` (`App.vue`, `main.ts`, app i18n, `CapabilityPanels.vue`, `ExecutorGate.vue`) |
52
- | `native-go-jobs` | Background job routes in `internal/app` and their page test |
52
+ | `native-go-jobs` | Background job routes in `internal/app` and a shell lifecycle test |
53
53
  | `native-go-delegate` | Delegate routes, the delegate background worker, the delegate `CapabilityPanels.vue` |
54
54
  | `native-go-root-ops` | The SDK's executor routes and `root.run` in `internal/app`, an example `root/whoami.sh`, and the Vue `ExecutorGate.vue` that holds the pages until the executor is approved |
55
55
  | `native-python` | Base: `dsm-package.yaml` (`backend.runtime: python`), the App in `backend/app` (`routes.py`, stub capability modules, `permissions.json`), unittest tests |
@@ -88,12 +88,10 @@ the single source of the SDK version and `frontend/package.json` pins
88
88
  so no UI peer override is needed. Tests use jsdom 30 for UI floating-layer styles.
89
89
 
90
90
  SDK 0.27.0 moves interactive NAS file operations to same-origin browser calls.
91
- The unused server-only `bg.browse` and file-import scaffold now return
92
- `unsupported`; custom file handlers need the SDK's
91
+ Custom file handlers use the SDK's
93
92
  [session transport migration](https://github.com/synopackageland/syno-pkg-land-sdk/blob/v0.27.0/docs/dsm-session-transport.md).
94
- Protected executor scaffolds need a released CLI with SDK 0.27.0 executor/lifecycle
95
- digests; CLI 0.26.0 does not include them and refuses those builds. Rebuilt protected
96
- executors follow normal administrator approval. No NAS acceptance is claimed.
93
+ Use CLI 0.27.0 for the matching SDK 0.27.0 executor/lifecycle digests. Rebuilt
94
+ protected executors follow normal administrator approval. No NAS acceptance is claimed.
97
95
 
98
96
  UI and i18n text, including the DSM glossary, omit terminal sentence periods.
99
97
  Keep punctuation between sentences and intentional loading ellipses.
@@ -214,3 +212,18 @@ the single-call path. Each batch result is handled separately; the shell stays
214
212
  visible while reads run. The backend permissions remain authoritative.
215
213
 
216
214
  Native Node Apps use the official [`Node.js_v22`](https://www.synology.com/en-us/dsm/packages/Node.js_v22) package. The official release history lists DSM 7 series; installation also depends on the model and DSM version supported by Package Center. This dependency does not certify all DSM 7 releases or install Node.js on unsupported models.
215
+
216
+ ### Background jobs
217
+
218
+ The jobs overlays submit files the App's own producer has already imported into
219
+ its private data directory. Submit `{key, name, input}` through `bg.jobs.submit`
220
+ (Go) or `hash.submit` (Python, Node.js and Rust); `input` is the absolute path of
221
+ that App-owned file. The Go handler and the bridge runtime confine reads to the
222
+ App data directory and keep the SDK's bounded private-copy input contract.
223
+ There is no NAS browse/import example or automatic file submission in either UI shell.
224
+
225
+ Keep the job controls and package-account workers for progress, cancellation and
226
+ pause/resume. Existing Go schedule routes reprocess retained, successful job
227
+ copies with explicit consent; they do not read a fresh source file on each run.
228
+ The bridge examples expose submission, lookup and cancellation through
229
+ `bg.submit`, `bg.get` and `bg.cancel`; the SDK's existing service surface is unchanged.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@synopackageland/templates",
3
- "version": "0.26.5",
3
+ "version": "0.27.1",
4
4
  "description": "Project templates for synopkgland init: native-go, native-python, native-node and native-rust (plain or Vue, with jobs, delegate and root-ops overlays), binary and compose.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -110,6 +110,12 @@ may redistribute; never copy Synology's.
110
110
 
111
111
  ## Background jobs (`jobs`)
112
112
 
113
+ Submit only files the App's own producer has already imported into its private
114
+ data directory, with `{key, name, input}`. The existing worker processes a
115
+ bounded private copy. Schedules reprocess that retained copy with explicit
116
+ consent; they never reread a source file. Keep submission, progress and
117
+ cancellation on the existing SDK contracts.
118
+
113
119
  The worker runs the App's Work for one claimed job at a time, as the package
114
120
  account. The Work receives the job's Task: it reads the private input copy,
115
121
  reports progress (`done`/`total`, `bytes`/`totalBytes`, `item`) and saves a
@@ -265,8 +271,7 @@ sweep forward the cancel instead of admitting it.
265
271
  The SDK runtime is the CGI: it checks the DSM session, the entry gate and
266
272
  permissions.json, then runs the App once per call, as the package account, and
267
273
  answers the browser itself for every refusal. The App only registers methods
268
- and asks the runtime for services with `ctx.runtime(op, params)`: `files.read`
269
- (the caller's file, `files: session`), `bg.submit`/`bg.get`/`bg.cancel` (the
274
+ and asks the runtime for services with `ctx.runtime(op, params)`: `bg.submit`/`bg.get`/`bg.cancel` (the
270
275
  caller's jobs, `jobs: true`, whose worker hashes each job's input), `root.run`
271
276
  (`rootOps`), `delegate.move_from_staging` (`delegate`) and `portal.status`. A
272
277
  service refusal is a code the browser may see; pass it on. The admin guard
@@ -399,3 +399,14 @@ SDK's `docs/shared-folder.md` for the whole flow.
399
399
  | Target CPUs | x86_64 and aarch64 DSM models (one SPK each). armv7 (DSM 7.2+ platforms `alpine`, `alpine4k`, `armada38x`, `monaco`) is opt-in: add it to `arches`; it covers the Go CGI (plain or Vue UI), jobs, daemon, root-ops and delegate. armv7 jobs, daemon and executor (root-ops, delegate) are built and checked locally but have not been verified on a NAS |
400
400
  | DSM | 7.1 or later declared (`os_min_ver`, change it with `init --min-dsm` or `build --min-dsm`). Installed and tested on DSM 7.4 and 7.3.2 (x86_64). armv7 was installed and tested on DSM 7.1.1 (`alpine4k`, Linux 3.10, where the bridge runs from the package tmp fallback) with administrator, AppPriv and unauthenticated requests; `armada38x` and `monaco` have not been run on a NAS. No x86_64 Linux 3.10 model has been tested. aarch64 SPKs are built the same way but have not been run on a NAS. |
401
401
  | Not supported | armv7 platforms only DSM 7.0/7.1 ship (`armada370`, `armada375`, `armadaxp`, `comcerto2k`); DSM 6, running anything as root without an administrator's approval |
402
+
403
+ ## Background job input
404
+
405
+ Jobs process an existing file imported by the App's producer into its private
406
+ data directory. The submission params are `{key, name, input}`: an idempotency
407
+ key, a display name and an absolute path inside that directory. The SDK keeps a
408
+ bounded private copy for the worker; no browser session or NAS picker is used.
409
+ Submit with `bg.jobs.submit`; use `bg.jobs.get` for progress and
410
+ `bg.jobs.cancel` to cancel. Pause/resume and existing schedule routes continue
411
+ to operate on retained imported copies. Schedules require explicit consent and
412
+ reprocess the fixed private copy, without rereading the source file.
@@ -4,16 +4,17 @@ import (
4
4
  "context"
5
5
  "encoding/json"
6
6
  "errors"
7
+ "io"
7
8
  "log"
8
9
  "net/http"
10
+ "os"
9
11
  "os/user"
10
- "path"
11
12
  "path/filepath"
13
+ "syscall"
12
14
  "time"
13
15
 
14
16
  "github.com/synopackageland/syno-pkg-land-sdk/api"
15
17
  "github.com/synopackageland/syno-pkg-land-sdk/background"
16
- "github.com/synopackageland/syno-pkg-land-sdk/filestation"
17
18
  )
18
19
 
19
20
  // workerFresh is how recent the worker heartbeat must be to count as running.
@@ -31,27 +32,20 @@ func osLookupUID(name string) string {
31
32
  return u.Uid
32
33
  }
33
34
 
34
- type backgroundFiles interface {
35
- Browse(ctx context.Context, c api.Caller, r *http.Request, folder string, offset int) (filestation.Page, error)
36
- ReadFile(ctx context.Context, c api.Caller, r *http.Request, folder, rel string) ([]byte, error)
37
- }
38
-
39
35
  type backgroundAPI struct {
40
- store *background.Store
41
- files backgroundFiles
36
+ store *background.Store
37
+ dataDir string
42
38
  }
43
39
 
44
- // BackgroundRoutes is the production assembly of the opt-in background jobs
45
- // API. `synopkgland init --with jobs` wires it in through background.go's
46
- // replacement of background_none.go; nothing else references it.
40
+ // BackgroundRoutes serves job controls for App-owned imported input.
47
41
  func BackgroundRoutes(dataDir string) []api.Route {
48
- return newBackgroundRoutes(background.NewRequestStore(filepath.Join(dataDir, "background")), filestation.Local(dataDir))
42
+ return newBackgroundRoutes(background.NewRequestStore(filepath.Join(dataDir, "background")), dataDir)
49
43
  }
50
44
 
51
45
  // Every request authenticates against DSM afresh. Owner routes are available
52
46
  // to signed-in users; schedule reapproval and owner cleanup are admin-only.
53
- func newBackgroundRoutes(store *background.Store, files backgroundFiles) []api.Route {
54
- b := backgroundAPI{store: store, files: files}
47
+ func newBackgroundRoutes(store *background.Store, dataDir string) []api.Route {
48
+ b := backgroundAPI{store: store, dataDir: dataDir}
55
49
  return []api.Route{
56
50
  api.HandleRequest("bg.status", b.owner(b.status)),
57
51
  api.HandleRequest("bg.schedules.list", b.owner(b.schedules)),
@@ -60,7 +54,6 @@ func newBackgroundRoutes(store *background.Store, files backgroundFiles) []api.R
60
54
  api.HandleRequest("bg.schedules.delete", b.owner(b.deleteSchedule)),
61
55
  api.HandleRequest("bg.schedules.enable", b.admin(b.enableSchedule)),
62
56
  api.HandleRequest("bg.jobs.purge", b.admin(b.purge)),
63
- api.HandleRequest("bg.browse", b.owner(b.browse)),
64
57
  api.HandleRequest("bg.jobs.submit", b.owner(b.submit)),
65
58
  api.HandleRequest("bg.jobs.list", b.owner(b.list)),
66
59
  api.HandleRequest("bg.jobs.get", b.owner(b.get)),
@@ -115,45 +108,28 @@ func workerAlive(w background.WorkerInfo, now time.Time) bool {
115
108
  return now.Sub(w.At) <= workerFresh
116
109
  }
117
110
 
118
- // browse lists what the caller's own File Station session can see, so
119
- // the panel can pick a file instead of typing a path. It grants nothing:
120
- // submit still reads through the same session.
121
- func (b backgroundAPI) browse(ctx context.Context, c api.Caller, r *http.Request, params json.RawMessage) (any, error) {
111
+ func (b backgroundAPI) submit(ctx context.Context, _ api.Caller, _ *http.Request, params json.RawMessage) (any, error) {
122
112
  var in struct {
123
- Folder string `json:"folder"`
124
- Offset int `json:"offset"`
113
+ Key string `json:"key"`
114
+ Name string `json:"name"`
115
+ Input string `json:"input"`
125
116
  }
126
117
  if err := decodeParams(params, &in); err != nil {
127
118
  return nil, err
128
119
  }
129
- if in.Offset < 0 {
130
- return nil, api.BadRequest("offset must not be negative")
131
- }
132
- return b.files.Browse(ctx, c, r, in.Folder, in.Offset)
133
- }
134
-
135
- func (b backgroundAPI) submit(ctx context.Context, c api.Caller, r *http.Request, params json.RawMessage) (any, error) {
136
- var in struct {
137
- Key string `json:"key"`
138
- Folder string `json:"folder"`
139
- Relative string `json:"relative"`
140
- }
141
- if err := decodeParams(params, &in); err != nil {
142
- return nil, err
143
- }
144
- if in.Key == "" || in.Folder == "" || in.Relative == "" {
145
- return nil, api.BadRequest("key, folder and relative are required")
120
+ if in.Key == "" || in.Name == "" || in.Input == "" {
121
+ return nil, api.BadRequest("key, name and input are required")
146
122
  }
147
123
  access := accessFrom(ctx)
148
124
  if !access.Owner.Valid() {
149
125
  return nil, &api.Error{Code: "identity_unavailable", Message: "DSM user UID could not be resolved"}
150
126
  }
151
- data, err := b.files.ReadFile(ctx, c, r, in.Folder, in.Relative)
127
+ data, err := b.readInput(in.Input)
152
128
  if err != nil {
153
129
  return nil, err
154
130
  }
155
131
  job, duplicate, err := b.store.Submit(ctx, background.SubmitRequest{
156
- Key: in.Key, Name: path.Base(in.Relative), Data: data, Submitter: access.Owner,
132
+ Key: in.Key, Name: in.Name, Data: data, Submitter: access.Owner,
157
133
  })
158
134
  if err != nil {
159
135
  return nil, backgroundError(err)
@@ -161,6 +137,41 @@ func (b backgroundAPI) submit(ctx context.Context, c api.Caller, r *http.Request
161
137
  return map[string]any{"job": job, "duplicate": duplicate}, nil
162
138
  }
163
139
 
140
+ // readInput accepts only an existing regular file inside the App data directory.
141
+ // The App's producer imports it first; jobs and schedules retain a private copy.
142
+ func (b backgroundAPI) readInput(input string) ([]byte, error) {
143
+ bad := api.BadRequest("input must be a regular file in the App data directory")
144
+ rel, err := filepath.Rel(b.dataDir, input)
145
+ if err != nil || !filepath.IsAbs(input) || !filepath.IsLocal(rel) {
146
+ return nil, bad
147
+ }
148
+ root, err := os.OpenRoot(b.dataDir)
149
+ if err != nil {
150
+ return nil, bad
151
+ }
152
+ defer root.Close()
153
+ f, err := root.OpenFile(rel, os.O_RDONLY|syscall.O_NONBLOCK, 0)
154
+ if err != nil {
155
+ return nil, bad
156
+ }
157
+ defer f.Close()
158
+ info, err := f.Stat()
159
+ if err != nil || !info.Mode().IsRegular() {
160
+ return nil, bad
161
+ }
162
+ if info.Size() > background.MaxInputBytes {
163
+ return nil, backgroundError(background.ErrTooLarge)
164
+ }
165
+ data, err := io.ReadAll(io.LimitReader(f, background.MaxInputBytes+1))
166
+ if err != nil {
167
+ return nil, bad
168
+ }
169
+ if len(data) > background.MaxInputBytes {
170
+ return nil, backgroundError(background.ErrTooLarge)
171
+ }
172
+ return data, nil
173
+ }
174
+
164
175
  func (b backgroundAPI) list(ctx context.Context, _ api.Caller, _ *http.Request, params json.RawMessage) (any, error) {
165
176
  if err := decodeParams(params, &struct{}{}); err != nil {
166
177
  return nil, err
@@ -28,7 +28,7 @@ var carol = stubAuth{identity: api.Identity{User: "carol"}}
28
28
 
29
29
  func ownerSubmit(t *testing.T, e *bgEnv, a api.Authenticator, key string) string {
30
30
  t.Helper()
31
- code, out := e.call(a, "bg.jobs.submit", `{"key":"`+key+`","folder":"/share","relative":"a.txt"}`)
31
+ code, out := e.call(a, "bg.jobs.submit", e.submitParams(key))
32
32
  if code != "" {
33
33
  t.Fatalf("submit %s: %s %v", key, code, out)
34
34
  }
@@ -103,7 +103,7 @@ func TestBackgroundPersonalQuotaAndAdminPurge(t *testing.T) {
103
103
  }
104
104
  ownerSubmit(t, e, bob, "one")
105
105
  ownerSubmit(t, e, bob, "two")
106
- if code, _ := e.call(bob, "bg.jobs.submit", `{"key":"three","folder":"/share","relative":"a.txt"}`); code != "owner-queue-full" {
106
+ if code, _ := e.call(bob, "bg.jobs.submit", e.submitParams("three")); code != "owner-queue-full" {
107
107
  t.Fatal(code)
108
108
  }
109
109
  ownerSubmit(t, e, carol, "one")
@@ -55,8 +55,4 @@ func TestBackgroundScheduleRoutesConsentOwnerAndAdmin(t *testing.T) {
55
55
  if code, _ := e.call(bob, "bg.schedules.delete", fmt.Sprintf(`{"id":%q}`, sid)); code != "" {
56
56
  t.Fatal(code)
57
57
  }
58
- // No scheduling route calls File Station, uses a root grant or stores a session.
59
- if e.files.calls != 1 {
60
- t.Fatalf("schedule read File Station %d", e.files.calls)
61
- }
62
58
  }
@@ -14,50 +14,30 @@ import (
14
14
 
15
15
  "github.com/synopackageland/syno-pkg-land-sdk/api"
16
16
  "github.com/synopackageland/syno-pkg-land-sdk/background"
17
- "github.com/synopackageland/syno-pkg-land-sdk/filestation"
18
17
  )
19
18
 
20
- type fakeFiles struct {
21
- data []byte
22
- err error
23
- calls int
24
- folder string
25
- rel string
26
- offset int
27
- page filestation.Page
28
- }
29
-
30
- func (f *fakeFiles) Browse(_ context.Context, _ api.Caller, _ *http.Request, folder string, offset int) (filestation.Page, error) {
31
- f.calls++
32
- f.folder, f.offset = folder, offset
33
- return f.page, f.err
34
- }
35
-
36
- func (f *fakeFiles) ReadFile(_ context.Context, _ api.Caller, _ *http.Request, folder, rel string) ([]byte, error) {
37
- f.calls++
38
- f.folder, f.rel = folder, rel
39
- return f.data, f.err
40
- }
41
-
42
19
  type bgEnv struct {
43
- t *testing.T
44
- store *background.Store
45
- files *fakeFiles
46
- srv map[string]*api.Server
20
+ t *testing.T
21
+ store *background.Store
22
+ dataDir string
23
+ srv map[string]*api.Server
47
24
  }
48
25
 
49
26
  func newBgEnv(t *testing.T) *bgEnv {
50
27
  lookupSubmitterUID = func(string) string { return "1024" }
51
28
  t.Cleanup(func() { lookupSubmitterUID = osLookupUID })
52
- store := background.NewStore(filepath.Join(t.TempDir(), "background"))
53
- files := &fakeFiles{data: []byte("hello")}
54
- return &bgEnv{t: t, store: store, files: files, srv: map[string]*api.Server{}}
29
+ dir := t.TempDir()
30
+ store := background.NewStore(filepath.Join(dir, "background"))
31
+ if err := os.WriteFile(filepath.Join(dir, "input.txt"), []byte("hello"), 0600); err != nil {
32
+ t.Fatal(err)
33
+ }
34
+ return &bgEnv{t: t, store: store, dataDir: dir, srv: map[string]*api.Server{}}
55
35
  }
56
36
 
57
37
  func (e *bgEnv) call(auth api.Authenticator, method, params string) (string, map[string]any) {
58
38
  e.t.Helper()
59
39
  // SDK policy provides owner routes immediately.
60
- routes := newBackgroundRoutes(e.store, e.files)
40
+ routes := newBackgroundRoutes(e.store, e.dataDir)
61
41
  srv, err := api.NewServerWithPermissions(auth, []byte(`{"schema":1,"default":"administrators","methods":{}}`), routes...)
62
42
  if err != nil {
63
43
  e.t.Fatal(err)
@@ -88,8 +68,7 @@ var bgSample = map[string]string{
88
68
  "bg.schedules.enable": `{"id":"missing","consent":true}`,
89
69
  "bg.status": `{}`,
90
70
  "bg.jobs.purge": `{"owner":{"user":"bob","uid":"1025"}}`,
91
- "bg.browse": `{"folder":"/share","offset":0}`,
92
- "bg.jobs.submit": `{"key":"k1","folder":"/share","relative":"a.txt"}`,
71
+ "bg.jobs.submit": `{"key":"k1","name":"a.txt","input":"/missing"}`,
93
72
  "bg.jobs.list": `{}`,
94
73
  "bg.jobs.get": `{"id":"` + strings.Repeat("a", 32) + `"}`,
95
74
  "bg.jobs.cancel": `{"id":"` + strings.Repeat("a", 32) + `"}`,
@@ -100,7 +79,7 @@ var bgSample = map[string]string{
100
79
 
101
80
  func TestBackgroundSDKPoliciesAuthenticateEveryRoute(t *testing.T) {
102
81
  e := newBgEnv(t)
103
- routes := newBackgroundRoutes(e.store, e.files)
82
+ routes := newBackgroundRoutes(e.store, e.dataDir)
104
83
  if len(routes) != len(bgSample) {
105
84
  t.Fatalf("%d routes, %d samples", len(routes), len(bgSample))
106
85
  }
@@ -149,55 +128,73 @@ func TestBackgroundStatusReportsLimitsAndWorker(t *testing.T) {
149
128
  }
150
129
  }
151
130
 
152
- func TestBackgroundSubmitAvailableOnFreshStore(t *testing.T) {
153
- e := newBgEnv(t)
154
- code, _ := e.call(alice, "bg.jobs.submit", bgSample["bg.jobs.submit"])
155
- if code != "" || e.files.calls != 1 {
156
- t.Fatalf("%q, NAS reads %d", code, e.files.calls)
131
+ func (e *bgEnv) submitParams(key string) string {
132
+ p, err := json.Marshal(map[string]string{"key": key, "name": "a.txt", "input": filepath.Join(e.dataDir, "input.txt")})
133
+ if err != nil {
134
+ e.t.Fatal(err)
157
135
  }
136
+ return string(p)
158
137
  }
159
138
 
160
- func TestBackgroundSubmitImportsSelectedFileAndIsIdempotent(t *testing.T) {
139
+ func TestBackgroundSubmitImportsAppInputAndIsIdempotent(t *testing.T) {
161
140
  e := newBgEnv(t)
162
- params := `{"key":"k1","folder":"/share","relative":"docs/a.txt"}`
141
+ params := e.submitParams("k1")
163
142
  code, out := e.call(alice, "bg.jobs.submit", params)
164
- job := data(out)["job"].(map[string]any)
165
- if code != "" || job["state"] != "queued" || job["name"] != "a.txt" || data(out)["duplicate"] != false {
143
+ if code != "" {
166
144
  t.Fatalf("%s %v", code, out)
167
145
  }
168
- if e.files.folder != "/share" || e.files.rel != "docs/a.txt" {
169
- t.Fatalf("adapter saw %q %q", e.files.folder, e.files.rel)
146
+ job := data(out)["job"].(map[string]any)
147
+ if job["state"] != "queued" || job["name"] != "a.txt" || data(out)["duplicate"] != false {
148
+ t.Fatal(out)
170
149
  }
171
150
  submitter := job["submitter"].(map[string]any)
172
151
  if submitter["user"] != "alice" || submitter["uid"] != "1024" {
173
- t.Fatalf("submitter: %v", submitter)
152
+ t.Fatal(submitter)
174
153
  }
175
154
  _, again := e.call(alice, "bg.jobs.submit", params)
176
155
  if data(again)["duplicate"] != true || data(again)["job"].(map[string]any)["id"] != job["id"] {
177
- t.Fatalf("duplicate: %v", again)
156
+ t.Fatal(again)
157
+ }
158
+ if err := os.WriteFile(filepath.Join(e.dataDir, "input.txt"), []byte("other"), 0600); err != nil {
159
+ t.Fatal(err)
178
160
  }
179
- e.files.data = []byte("other")
180
161
  if code, _ := e.call(alice, "bg.jobs.submit", params); code != "conflict" {
181
- t.Fatalf("same key with different bytes: %q", code)
162
+ t.Fatalf("different bytes: %q", code)
182
163
  }
183
164
  }
184
165
 
185
- func TestBackgroundSubmitPassesAdapterRefusalsThrough(t *testing.T) {
166
+ func TestBackgroundSubmitRejectsExternalAndOversizedInput(t *testing.T) {
186
167
  e := newBgEnv(t)
187
- e.files.err = &api.Error{Code: "limit-exceeded", Message: "x"}
188
- if code, _ := e.call(alice, "bg.jobs.submit", bgSample["bg.jobs.submit"]); code != "limit-exceeded" {
189
- t.Fatalf("%q", code)
168
+ outside := filepath.Join(t.TempDir(), "outside")
169
+ if err := os.WriteFile(outside, []byte("private"), 0600); err != nil {
170
+ t.Fatal(err)
190
171
  }
191
- if jobs, _ := e.store.List(context.Background()); len(jobs) != 0 {
192
- t.Fatal("a failed import must never enter the queue")
172
+ if err := os.Symlink(outside, filepath.Join(e.dataDir, "escape")); err != nil {
173
+ t.Fatal(err)
174
+ }
175
+ for _, input := range []string{outside, "input.txt", filepath.Join(e.dataDir, "escape"), e.dataDir} {
176
+ p, _ := json.Marshal(map[string]string{"key": "bad", "name": "a.txt", "input": input})
177
+ if code, _ := e.call(alice, "bg.jobs.submit", string(p)); code != "bad_request" {
178
+ t.Fatalf("%s: %s", input, code)
179
+ }
180
+ }
181
+ if err := os.WriteFile(filepath.Join(e.dataDir, "input.txt"), make([]byte, background.MaxInputBytes+1), 0600); err != nil {
182
+ t.Fatal(err)
183
+ }
184
+ if code, _ := e.call(alice, "bg.jobs.submit", e.submitParams("big")); code != "limit-exceeded" {
185
+ t.Fatal(code)
186
+ }
187
+ jobs, err := e.store.List(context.Background())
188
+ if err != nil || len(jobs) != 0 {
189
+ t.Fatalf("invalid input queued: %v %v", jobs, err)
193
190
  }
194
191
  }
195
192
 
196
193
  func TestBackgroundSubmitValidatesParams(t *testing.T) {
197
194
  e := newBgEnv(t)
198
195
  for _, p := range []string{
199
- `{}`, `{"key":"k","folder":"/share","relative":"a","extra":1}`, `{"key":"bad key","folder":"/share","relative":"a"}`,
200
- `{"key":"k","folder":"/share","relative":""}`,
196
+ `{}`, `{"key":"k","name":"a","input":"/a","extra":1}`, e.submitParams("bad key"),
197
+ `{"key":"k","name":"a","input":""}`,
201
198
  } {
202
199
  if code, _ := e.call(alice, "bg.jobs.submit", p); code != "bad_request" {
203
200
  t.Errorf("%s: %q", p, code)
@@ -210,19 +207,19 @@ func TestBackgroundQueueFullAndQuotaErrorsHaveStableCodes(t *testing.T) {
210
207
  for i := 0; i < background.MaxQueued; i++ {
211
208
  lookupSubmitterUID = func(string) string { return fmt.Sprint(1024 + i/2) }
212
209
  key := "k" + string(rune('a'+i))
213
- if code, _ := e.call(alice, "bg.jobs.submit", `{"key":"`+key+`","folder":"/share","relative":"a.txt"}`); code != "" {
210
+ if code, _ := e.call(alice, "bg.jobs.submit", e.submitParams(key)); code != "" {
214
211
  t.Fatalf("%d: %q", i, code)
215
212
  }
216
213
  }
217
214
  lookupSubmitterUID = func(string) string { return "9999" }
218
- if code, _ := e.call(alice, "bg.jobs.submit", `{"key":"more","folder":"/share","relative":"a.txt"}`); code != "queue-full" {
215
+ if code, _ := e.call(alice, "bg.jobs.submit", e.submitParams("more")); code != "queue-full" {
219
216
  t.Fatalf("%q", code)
220
217
  }
221
218
  }
222
219
 
223
220
  func TestBackgroundListGetCancelAndResult(t *testing.T) {
224
221
  e := newBgEnv(t)
225
- _, out := e.call(alice, "bg.jobs.submit", `{"key":"k1","folder":"/share","relative":"a.txt"}`)
222
+ _, out := e.call(alice, "bg.jobs.submit", e.submitParams("k1"))
226
223
  id := data(out)["job"].(map[string]any)["id"].(string)
227
224
  idp := `{"id":"` + id + `"}`
228
225
 
@@ -260,7 +257,7 @@ func TestBackgroundListGetCancelAndResult(t *testing.T) {
260
257
 
261
258
  func TestBackgroundCancelQueuedJob(t *testing.T) {
262
259
  e := newBgEnv(t)
263
- _, out := e.call(alice, "bg.jobs.submit", `{"key":"k1","folder":"/share","relative":"a.txt"}`)
260
+ _, out := e.call(alice, "bg.jobs.submit", e.submitParams("k1"))
264
261
  id := data(out)["job"].(map[string]any)["id"].(string)
265
262
  code, out := e.call(alice, "bg.jobs.cancel", `{"id":"`+id+`"}`)
266
263
  if code != "" || data(out)["job"].(map[string]any)["state"] != "canceled" {
@@ -270,7 +267,7 @@ func TestBackgroundCancelQueuedJob(t *testing.T) {
270
267
 
271
268
  func TestBackgroundPauseAndResumeQueuedJob(t *testing.T) {
272
269
  e := newBgEnv(t)
273
- _, out := e.call(alice, "bg.jobs.submit", `{"key":"k1","folder":"/share","relative":"a.txt"}`)
270
+ _, out := e.call(alice, "bg.jobs.submit", e.submitParams("k1"))
274
271
  idp := `{"id":"` + data(out)["job"].(map[string]any)["id"].(string) + `"}`
275
272
  for method, state := range map[string]string{"bg.jobs.pause": "paused", "bg.jobs.resume": "queued"} {
276
273
  if code, out := e.call(alice, method, idp); code != "" || data(out)["job"].(map[string]any)["state"] != state {
@@ -296,48 +293,6 @@ func TestBackgroundWorkerAliveExpires(t *testing.T) {
296
293
  }
297
294
  }
298
295
 
299
- func TestBackgroundBrowseListsThroughTheCallersSession(t *testing.T) {
300
- e := newBgEnv(t)
301
- e.files.page = filestation.Page{Files: []filestation.Entry{{Name: "a.txt", Path: "/share/a.txt"}}, Total: 1}
302
- code, out := e.call(alice, "bg.browse", `{"folder":"/share","offset":100}`)
303
- if code != "" {
304
- t.Fatalf("%s %v", code, out)
305
- }
306
- if e.files.folder != "/share" || e.files.offset != 100 {
307
- t.Fatalf("browsed %q at %d", e.files.folder, e.files.offset)
308
- }
309
- files := data(out)["files"].([]any)
310
- if len(files) != 1 || files[0].(map[string]any)["path"] != "/share/a.txt" {
311
- t.Fatalf("page %v", out)
312
- }
313
- }
314
-
315
- func TestBackgroundBrowseWithoutFolderListsTheShares(t *testing.T) {
316
- e := newBgEnv(t)
317
- if code, out := e.call(alice, "bg.browse", `{}`); code != "" {
318
- t.Fatalf("%s %v", code, out)
319
- }
320
- if e.files.folder != "" || e.files.offset != 0 {
321
- t.Fatalf("browsed %q at %d", e.files.folder, e.files.offset)
322
- }
323
- }
324
-
325
- func TestBackgroundBrowseValidatesParamsAndPassesRefusalsThrough(t *testing.T) {
326
- e := newBgEnv(t)
327
- for _, params := range []string{`{"offset":-1}`, `{"folder":"/share","extra":1}`, `{"offset":"1"}`} {
328
- if code, _ := e.call(alice, "bg.browse", params); code != "bad_request" {
329
- t.Errorf("%s: %q", params, code)
330
- }
331
- }
332
- if e.files.calls != 0 {
333
- t.Fatal("invalid params must not reach the NAS")
334
- }
335
- e.files.err = &api.Error{Code: "denied", Message: "no"}
336
- if code, _ := e.call(alice, "bg.browse", `{"folder":"/share"}`); code != "denied" {
337
- t.Fatalf("got %q", code)
338
- }
339
- }
340
-
341
296
  func TestBackgroundListWithoutJobsIsAnEmptyArray(t *testing.T) {
342
297
  e := newBgEnv(t)
343
298
  _, out := e.call(alice, "bg.jobs.list", `{}`)
@@ -4,7 +4,6 @@ import (
4
4
  "github.com/synopackageland/syno-pkg-land-sdk/api"
5
5
  "github.com/synopackageland/syno-pkg-land-sdk/background"
6
6
  "github.com/synopackageland/syno-pkg-land-sdk/delegate"
7
- "github.com/synopackageland/syno-pkg-land-sdk/filestation"
8
7
  "path/filepath"
9
8
  )
10
9
 
@@ -16,10 +15,5 @@ func DelegateRoutes(cfg Config, scope string) []api.Route {
16
15
  if err == nil {
17
16
  service.Destinations, service.Operations, service.Lifetime = settings.Destinations, settings.Operations, settings.Lifetime
18
17
  }
19
- if cfg.SessionFiles != nil {
20
- service.SessionFiles = cfg.SessionFiles
21
- } else {
22
- service.SessionFiles = filestation.Local(cfg.DataDir)
23
- }
24
18
  return service.Routes()
25
19
  }
@@ -16,7 +16,6 @@ import (
16
16
 
17
17
  func init() {
18
18
  // The generic route tests need valid params for every background route.
19
- // The SDK refuses retired backend session relays before reading a file.
20
19
  // No jobs or schedules exist in its fresh data directory.
21
20
  const id = `{"id":"missing"}`
22
21
  sampleParams["bg.jobs.purge"] = `{"owner":{"user":"missing","uid":"9999"}}`
@@ -30,16 +29,14 @@ func init() {
30
29
  sampleOutcome["bg.schedules.delete"] = "not_found"
31
30
  sampleOutcome["bg.schedules.enable"] = "not_found"
32
31
  sampleParams["bg.status"] = `{}`
33
- sampleParams["bg.browse"] = `{}`
34
- sampleParams["bg.jobs.submit"] = `{"key":"k1","folder":"/share","relative":"a.bin"}`
32
+ sampleParams["bg.jobs.submit"] = `{"key":"k1","name":"a.bin","input":"/missing"}`
35
33
  sampleParams["bg.jobs.list"] = `{}`
36
34
  sampleParams["bg.jobs.get"] = id
37
35
  sampleParams["bg.jobs.cancel"] = id
38
36
  sampleParams["bg.jobs.pause"] = id
39
37
  sampleParams["bg.jobs.resume"] = id
40
38
  sampleParams["bg.jobs.result"] = id
41
- sampleOutcome["bg.browse"] = "unsupported"
42
- sampleOutcome["bg.jobs.submit"] = "unsupported"
39
+ sampleOutcome["bg.jobs.submit"] = "bad_request"
43
40
  sampleOutcome["bg.jobs.get"] = "not_found"
44
41
  sampleOutcome["bg.jobs.cancel"] = "not_found"
45
42
  sampleOutcome["bg.jobs.pause"] = "not_found"
@@ -72,7 +69,7 @@ func TestBackgroundRequestSubmitBusyAndProductionConstruction(t *testing.T) {
72
69
  }
73
70
  defer syscall.Flock(int(f.Fd()), syscall.LOCK_UN)
74
71
  start := time.Now()
75
- code, out := e.call(alice, "bg.jobs.submit", bgSample["bg.jobs.submit"])
72
+ code, out := e.call(alice, "bg.jobs.submit", e.submitParams("k1"))
76
73
  if code != "jobs_busy" || time.Since(start) > background.RequestLockTimeout+time.Second {
77
74
  t.Fatalf("busy submit: %s %+v", code, out)
78
75
  }
@@ -0,0 +1,19 @@
1
+ // @vitest-environment jsdom
2
+ import {expect,test,vi} from 'vitest'
3
+ import {nextTick} from 'vue'
4
+ import {mount} from '../src/main'
5
+ import {dsmWindow} from './context'
6
+ async function settle(){for(let i=0;i<20;i++){await Promise.resolve();await nextTick()}}
7
+ test('a jobs project opens its shell without starting a job',async()=>{
8
+ const call=vi.fn(async(method:string)=>{
9
+ if(method==='app.status')return {package:'Jobs',version:'1',user:'alice',admin:false}
10
+ throw {code:'unknown_method'}
11
+ })
12
+ const root=document.createElement('div');document.body.append(root)
13
+ const app=mount(root,dsmWindow({call}))
14
+ try{
15
+ await settle()
16
+ expect(root.querySelector('[data-app-status]')).not.toBeNull()
17
+ expect(call.mock.calls.some(([method])=>method.startsWith('bg.'))).toBe(false)
18
+ }finally{app.unmount();root.remove()}
19
+ })