@pippit-dev/cli 1.0.49 → 1.0.51

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.
@@ -1,7 +1,7 @@
1
1
  XYQ Canvas Command Runtime - Bundled Software Notices
2
2
 
3
3
  Generated from the exact esbuild input graph. No build paths or timestamps are included.
4
- 12 Pippit first-party modules are bundled and are not listed by internal package name.
4
+ 14 Pippit first-party modules are bundled and are not listed by internal package name.
5
5
 
6
6
  ===== @babel/runtime@7.29.7 =====
7
7
  License metadata: MIT
@@ -304,6 +304,212 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
304
304
  See the License for the specific language governing permissions and
305
305
  limitations under the License.
306
306
 
307
+ ===== @swc/helpers@0.5.6 =====
308
+ License metadata: Apache-2.0
309
+
310
+ --- LICENSE ---
311
+ Apache License
312
+ Version 2.0, January 2004
313
+ http://www.apache.org/licenses/
314
+
315
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
316
+
317
+ 1. Definitions.
318
+
319
+ "License" shall mean the terms and conditions for use, reproduction,
320
+ and distribution as defined by Sections 1 through 9 of this document.
321
+
322
+ "Licensor" shall mean the copyright owner or entity authorized by
323
+ the copyright owner that is granting the License.
324
+
325
+ "Legal Entity" shall mean the union of the acting entity and all
326
+ other entities that control, are controlled by, or are under common
327
+ control with that entity. For the purposes of this definition,
328
+ "control" means (i) the power, direct or indirect, to cause the
329
+ direction or management of such entity, whether by contract or
330
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
331
+ outstanding shares, or (iii) beneficial ownership of such entity.
332
+
333
+ "You" (or "Your") shall mean an individual or Legal Entity
334
+ exercising permissions granted by this License.
335
+
336
+ "Source" form shall mean the preferred form for making modifications,
337
+ including but not limited to software source code, documentation
338
+ source, and configuration files.
339
+
340
+ "Object" form shall mean any form resulting from mechanical
341
+ transformation or translation of a Source form, including but
342
+ not limited to compiled object code, generated documentation,
343
+ and conversions to other media types.
344
+
345
+ "Work" shall mean the work of authorship, whether in Source or
346
+ Object form, made available under the License, as indicated by a
347
+ copyright notice that is included in or attached to the work
348
+ (an example is provided in the Appendix below).
349
+
350
+ "Derivative Works" shall mean any work, whether in Source or Object
351
+ form, that is based on (or derived from) the Work and for which the
352
+ editorial revisions, annotations, elaborations, or other modifications
353
+ represent, as a whole, an original work of authorship. For the purposes
354
+ of this License, Derivative Works shall not include works that remain
355
+ separable from, or merely link (or bind by name) to the interfaces of,
356
+ the Work and Derivative Works thereof.
357
+
358
+ "Contribution" shall mean any work of authorship, including
359
+ the original version of the Work and any modifications or additions
360
+ to that Work or Derivative Works thereof, that is intentionally
361
+ submitted to Licensor for inclusion in the Work by the copyright owner
362
+ or by an individual or Legal Entity authorized to submit on behalf of
363
+ the copyright owner. For the purposes of this definition, "submitted"
364
+ means any form of electronic, verbal, or written communication sent
365
+ to the Licensor or its representatives, including but not limited to
366
+ communication on electronic mailing lists, source code control systems,
367
+ and issue tracking systems that are managed by, or on behalf of, the
368
+ Licensor for the purpose of discussing and improving the Work, but
369
+ excluding communication that is conspicuously marked or otherwise
370
+ designated in writing by the copyright owner as "Not a Contribution."
371
+
372
+ "Contributor" shall mean Licensor and any individual or Legal Entity
373
+ on behalf of whom a Contribution has been received by Licensor and
374
+ subsequently incorporated within the Work.
375
+
376
+ 2. Grant of Copyright License. Subject to the terms and conditions of
377
+ this License, each Contributor hereby grants to You a perpetual,
378
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
379
+ copyright license to reproduce, prepare Derivative Works of,
380
+ publicly display, publicly perform, sublicense, and distribute the
381
+ Work and such Derivative Works in Source or Object form.
382
+
383
+ 3. Grant of Patent License. Subject to the terms and conditions of
384
+ this License, each Contributor hereby grants to You a perpetual,
385
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
386
+ (except as stated in this section) patent license to make, have made,
387
+ use, offer to sell, sell, import, and otherwise transfer the Work,
388
+ where such license applies only to those patent claims licensable
389
+ by such Contributor that are necessarily infringed by their
390
+ Contribution(s) alone or by combination of their Contribution(s)
391
+ with the Work to which such Contribution(s) was submitted. If You
392
+ institute patent litigation against any entity (including a
393
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
394
+ or a Contribution incorporated within the Work constitutes direct
395
+ or contributory patent infringement, then any patent licenses
396
+ granted to You under this License for that Work shall terminate
397
+ as of the date such litigation is filed.
398
+
399
+ 4. Redistribution. You may reproduce and distribute copies of the
400
+ Work or Derivative Works thereof in any medium, with or without
401
+ modifications, and in Source or Object form, provided that You
402
+ meet the following conditions:
403
+
404
+ (a) You must give any other recipients of the Work or
405
+ Derivative Works a copy of this License; and
406
+
407
+ (b) You must cause any modified files to carry prominent notices
408
+ stating that You changed the files; and
409
+
410
+ (c) You must retain, in the Source form of any Derivative Works
411
+ that You distribute, all copyright, patent, trademark, and
412
+ attribution notices from the Source form of the Work,
413
+ excluding those notices that do not pertain to any part of
414
+ the Derivative Works; and
415
+
416
+ (d) If the Work includes a "NOTICE" text file as part of its
417
+ distribution, then any Derivative Works that You distribute must
418
+ include a readable copy of the attribution notices contained
419
+ within such NOTICE file, excluding those notices that do not
420
+ pertain to any part of the Derivative Works, in at least one
421
+ of the following places: within a NOTICE text file distributed
422
+ as part of the Derivative Works; within the Source form or
423
+ documentation, if provided along with the Derivative Works; or,
424
+ within a display generated by the Derivative Works, if and
425
+ wherever such third-party notices normally appear. The contents
426
+ of the NOTICE file are for informational purposes only and
427
+ do not modify the License. You may add Your own attribution
428
+ notices within Derivative Works that You distribute, alongside
429
+ or as an addendum to the NOTICE text from the Work, provided
430
+ that such additional attribution notices cannot be construed
431
+ as modifying the License.
432
+
433
+ You may add Your own copyright statement to Your modifications and
434
+ may provide additional or different license terms and conditions
435
+ for use, reproduction, or distribution of Your modifications, or
436
+ for any such Derivative Works as a whole, provided Your use,
437
+ reproduction, and distribution of the Work otherwise complies with
438
+ the conditions stated in this License.
439
+
440
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
441
+ any Contribution intentionally submitted for inclusion in the Work
442
+ by You to the Licensor shall be under the terms and conditions of
443
+ this License, without any additional terms or conditions.
444
+ Notwithstanding the above, nothing herein shall supersede or modify
445
+ the terms of any separate license agreement you may have executed
446
+ with Licensor regarding such Contributions.
447
+
448
+ 6. Trademarks. This License does not grant permission to use the trade
449
+ names, trademarks, service marks, or product names of the Licensor,
450
+ except as required for reasonable and customary use in describing the
451
+ origin of the Work and reproducing the content of the NOTICE file.
452
+
453
+ 7. Disclaimer of Warranty. Unless required by applicable law or
454
+ agreed to in writing, Licensor provides the Work (and each
455
+ Contributor provides its Contributions) on an "AS IS" BASIS,
456
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
457
+ implied, including, without limitation, any warranties or conditions
458
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
459
+ PARTICULAR PURPOSE. You are solely responsible for determining the
460
+ appropriateness of using or redistributing the Work and assume any
461
+ risks associated with Your exercise of permissions under this License.
462
+
463
+ 8. Limitation of Liability. In no event and under no legal theory,
464
+ whether in tort (including negligence), contract, or otherwise,
465
+ unless required by applicable law (such as deliberate and grossly
466
+ negligent acts) or agreed to in writing, shall any Contributor be
467
+ liable to You for damages, including any direct, indirect, special,
468
+ incidental, or consequential damages of any character arising as a
469
+ result of this License or out of the use or inability to use the
470
+ Work (including but not limited to damages for loss of goodwill,
471
+ work stoppage, computer failure or malfunction, or any and all
472
+ other commercial damages or losses), even if such Contributor
473
+ has been advised of the possibility of such damages.
474
+
475
+ 9. Accepting Warranty or Additional Liability. While redistributing
476
+ the Work or Derivative Works thereof, You may choose to offer,
477
+ and charge a fee for, acceptance of support, warranty, indemnity,
478
+ or other liability obligations and/or rights consistent with this
479
+ License. However, in accepting such obligations, You may act only
480
+ on Your own behalf and on Your sole responsibility, not on behalf
481
+ of any other Contributor, and only if You agree to indemnify,
482
+ defend, and hold each Contributor harmless for any liability
483
+ incurred by, or claims asserted against, such Contributor by reason
484
+ of your accepting any such warranty or additional liability.
485
+
486
+ END OF TERMS AND CONDITIONS
487
+
488
+ APPENDIX: How to apply the Apache License to your work.
489
+
490
+ To apply the Apache License to your work, attach the following
491
+ boilerplate notice, with the fields enclosed by brackets "[]"
492
+ replaced with your own identifying information. (Don't include
493
+ the brackets!) The text should be enclosed in the appropriate
494
+ comment syntax for the file format. We also recommend that a
495
+ file or class name and description of purpose be included on the
496
+ same "printed page" as the copyright notice for easier
497
+ identification within third-party archives.
498
+
499
+ Copyright [yyyy] [name of copyright owner]
500
+
501
+ Licensed under the Apache License, Version 2.0 (the "License");
502
+ you may not use this file except in compliance with the License.
503
+ You may obtain a copy of the License at
504
+
505
+ http://www.apache.org/licenses/LICENSE-2.0
506
+
507
+ Unless required by applicable law or agreed to in writing, software
508
+ distributed under the License is distributed on an "AS IS" BASIS,
509
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
510
+ See the License for the specific language governing permissions and
511
+ limitations under the License.
512
+
307
513
  ===== dagre@0.8.5 =====
308
514
  License metadata: MIT
309
515
 
@@ -546,32 +752,6 @@ maintained libraries used by this software which have their own
546
752
  licenses; we recommend you read them, as their terms may differ from the
547
753
  terms above.
548
754
 
549
- ===== three@0.184.0 =====
550
- License metadata: MIT
551
-
552
- --- LICENSE ---
553
- The MIT License
554
-
555
- Copyright © 2010-2026 three.js authors
556
-
557
- Permission is hereby granted, free of charge, to any person obtaining a copy
558
- of this software and associated documentation files (the "Software"), to deal
559
- in the Software without restriction, including without limitation the rights
560
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
561
- copies of the Software, and to permit persons to whom the Software is
562
- furnished to do so, subject to the following conditions:
563
-
564
- The above copyright notice and this permission notice shall be included in
565
- all copies or substantial portions of the Software.
566
-
567
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
568
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
569
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
570
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
571
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
572
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
573
- THE SOFTWARE.
574
-
575
755
  ===== tslib@2.6.2 =====
576
756
  License metadata: 0BSD
577
757
 
@@ -1,2 +1,2 @@
1
- 8e14b9a2c496491c2ee44da3ed950ac8301b67981dfaba3ab1e042cf8b937298 xyq-canvas-command-runtime.cjs
2
- 3b97217c41dfb3c298185c80b1e70c2b469f552450e53d00fc1dcf7098740ffb xyq-canvas-command-runtime.cjs.LEGAL.txt
1
+ 7e45eb4e7bb2323fd1a0f5bc56b731247076f9ae8171f46d01ba4d6774de1b0f xyq-canvas-command-runtime.cjs
2
+ c29b5a61e7c48ec377826ec7ff6a6f2b16f0824e5a4b7f278f622524c694e047 xyq-canvas-command-runtime.cjs.LEGAL.txt
@@ -0,0 +1,152 @@
1
+ package canvas
2
+
3
+ import (
4
+ "bytes"
5
+ "encoding/json"
6
+ "fmt"
7
+ "reflect"
8
+ "strconv"
9
+ "strings"
10
+ )
11
+
12
+ var imageSubjectFields = []string{"appearanceinfo", "sourceinfos"}
13
+
14
+ func isImageSubjectField(field string) bool {
15
+ name := strings.ToLower(field)
16
+ return name == imageSubjectFields[0] || name == imageSubjectFields[1]
17
+ }
18
+
19
+ func nodeBindingContent(node map[string]json.RawMessage) map[string]json.RawMessage {
20
+ raw, _ := identityField(node, "content")
21
+ var content map[string]json.RawMessage
22
+ _ = json.Unmarshal(raw, &content)
23
+ return content
24
+ }
25
+
26
+ func decodeBindingValue(raw json.RawMessage) any {
27
+ decoder := json.NewDecoder(bytes.NewReader(raw))
28
+ decoder.UseNumber()
29
+ var value any
30
+ _ = decoder.Decode(&value)
31
+ return value
32
+ }
33
+
34
+ func hasSubjectBinding(value any) bool {
35
+ switch value := value.(type) {
36
+ case nil:
37
+ return false
38
+ case string:
39
+ return strings.TrimSpace(value) != ""
40
+ case []any:
41
+ return len(value) > 0
42
+ case map[string]any:
43
+ return len(value) > 0
44
+ default:
45
+ return true
46
+ }
47
+ }
48
+
49
+ func replacesImageSubjectBinding(patch PatchEntry) bool {
50
+ if patch.Path != "" || patch.Op != "replace" {
51
+ return false
52
+ }
53
+ var node map[string]json.RawMessage
54
+ if json.Unmarshal(patch.Value, &node) != nil {
55
+ return false
56
+ }
57
+ kind, _ := identityString(node, "type")
58
+ if kind != "biz/image" {
59
+ return false
60
+ }
61
+ for field, raw := range nodeBindingContent(node) {
62
+ if isImageSubjectField(field) && hasSubjectBinding(decodeBindingValue(raw)) {
63
+ return true
64
+ }
65
+ }
66
+ return false
67
+ }
68
+
69
+ // Legacy fields may be retained or cleared, but new image bindings use the
70
+ // image protocol. Do not infer a role/scene conversion from arbitrary content.
71
+ func validateImageSubjectBinding(nodeID string, node, previous map[string]json.RawMessage) error {
72
+ content := nodeBindingContent(node)
73
+ oldContent := nodeBindingContent(previous)
74
+ oldType, _ := identityString(previous, "type")
75
+ for field, raw := range content {
76
+ if !isImageSubjectField(field) {
77
+ continue
78
+ }
79
+ value := decodeBindingValue(raw)
80
+ if !hasSubjectBinding(value) {
81
+ continue
82
+ }
83
+ if oldType == "biz/image" && reflect.DeepEqual(value, decodeBindingValue(oldContent[field])) {
84
+ continue
85
+ }
86
+ return mediaIdentityError(nodeID, "/content/"+field,
87
+ "biz/image cannot bind role/scene content; use content.pippitAssetId for an image or a biz/role or biz/scene node")
88
+ }
89
+ return nil
90
+ }
91
+
92
+ // Project only the selected identity subtree, including nested subject fields.
93
+ // RFC 6902 array operations must not collapse a child patch into its parent.
94
+ func projectMediaIdentityValue(raw json.RawMessage, parts []string, patch PatchEntry) (json.RawMessage, error) {
95
+ if len(parts) == 0 {
96
+ return patch.Value, nil
97
+ }
98
+ value := bytes.TrimSpace(raw)
99
+ if len(value) == 0 {
100
+ return nil, fmt.Errorf("cannot validate a media identity without its content base")
101
+ }
102
+ key := parts[0]
103
+ if value[0] == '{' {
104
+ var object map[string]json.RawMessage
105
+ if err := json.Unmarshal(value, &object); err != nil {
106
+ return nil, err
107
+ }
108
+ if len(parts) == 1 && patch.Op == "remove" {
109
+ delete(object, key)
110
+ } else {
111
+ next, err := projectMediaIdentityValue(object[key], parts[1:], patch)
112
+ if err != nil {
113
+ return nil, err
114
+ }
115
+ object[key] = next
116
+ }
117
+ return json.Marshal(object)
118
+ }
119
+ if value[0] != '[' {
120
+ return nil, fmt.Errorf("cannot validate a nested identity patch on a scalar")
121
+ }
122
+ var array []json.RawMessage
123
+ if err := json.Unmarshal(value, &array); err != nil {
124
+ return nil, err
125
+ }
126
+ index, err := strconv.Atoi(key)
127
+ if key == "-" && len(parts) == 1 && patch.Op == "add" {
128
+ index, err = len(array), nil
129
+ }
130
+ if err != nil || index < 0 || index > len(array) || (len(key) > 1 && key[0] == '0') {
131
+ return nil, fmt.Errorf("invalid media identity array index %q", key)
132
+ }
133
+ if len(parts) == 1 && patch.Op == "add" {
134
+ array = append(array, nil)
135
+ copy(array[index+1:], array[index:])
136
+ array[index] = patch.Value
137
+ } else {
138
+ if index == len(array) {
139
+ return nil, fmt.Errorf("media identity array index %q does not exist", key)
140
+ }
141
+ if len(parts) == 1 && patch.Op == "remove" {
142
+ array = append(array[:index], array[index+1:]...)
143
+ } else {
144
+ next, err := projectMediaIdentityValue(array[index], parts[1:], patch)
145
+ if err != nil {
146
+ return nil, err
147
+ }
148
+ array[index] = next
149
+ }
150
+ }
151
+ return json.Marshal(array)
152
+ }
@@ -0,0 +1,137 @@
1
+ package canvas
2
+
3
+ import (
4
+ "context"
5
+ "encoding/json"
6
+ "fmt"
7
+ "strings"
8
+ "testing"
9
+
10
+ "github.com/Pippit-dev/pippit-cli/internal/common"
11
+ )
12
+
13
+ func imageBindingFixture(node string, patches []PatchEntry) (ApplyOptions, *common.Runner, *int) {
14
+ opts, _, writes := applyIdentityFixture(patches, imageMaterial())
15
+ client := &fakeClient{send: func(_ context.Context, path string, body, out any) error {
16
+ switch path {
17
+ case QueryPath:
18
+ request := body.(queryRequest)
19
+ var assets []json.RawMessage
20
+ for _, id := range request.PippitAssetIDs {
21
+ if id == testNodeID {
22
+ content, _ := json.Marshal(node)
23
+ assets = append(assets, json.RawMessage(fmt.Sprintf(`{"PippitAssetID":"%s","TextInfo":{"content":%s},"version":5}`, id, content)))
24
+ } else if id == testPippitID {
25
+ assets = append(assets, json.RawMessage(imageMaterial()))
26
+ }
27
+ }
28
+ payload, _ := json.Marshal(map[string]any{"ret": "0", "data": map[string]any{"Assets": assets}})
29
+ return decodeInto(out, string(payload))
30
+ case ApplyPath:
31
+ *writes++
32
+ return decodeInto(out, fmt.Sprintf(`{"ret":"0","data":{"results":[{"transaction_id":"tx","status":"ack","asset_versions":{"%s":6}}]}}`, testNodeID))
33
+ default:
34
+ return fmt.Errorf("unexpected request %s", path)
35
+ }
36
+ }}
37
+ return opts, runnerWithClient(client), writes
38
+ }
39
+
40
+ func bindingPatch(op, path, value string) PatchEntry {
41
+ return PatchEntry{AssetID: testNodeID, Op: op, Path: path, Value: json.RawMessage(value)}
42
+ }
43
+
44
+ func TestApplyMediaIdentityRejectsRoleFieldsOnImageBeforeWrite(t *testing.T) {
45
+ blank := `{"type":"biz/image","content":{"caption":"draft","generation":{}}}`
46
+ for _, test := range []struct {
47
+ name, node string
48
+ patches []PatchEntry
49
+ }{
50
+ {"original-upload", blank, []PatchEntry{
51
+ bindingPatch("add", "/content/appearanceInfo", `{"pippitAssetId":"image-material"}`),
52
+ bindingPatch("add", "/content/generation", `{"source":"uploaded"}`),
53
+ bindingPatch("add", "/content/sourceInfos", `{"image-material":{"source":"uploaded"}}`),
54
+ }},
55
+ {"source-map", blank, []PatchEntry{bindingPatch("add", "/content/sourceInfos", `{"image-material":{}}`)}},
56
+ {"source-array", blank, []PatchEntry{bindingPatch("add", "/content/sourceInfos", `[{"pippitAssetId":"image-material"}]`)}},
57
+ {"root-create", "", []PatchEntry{bindingPatch("add", "", `{"type":"biz/image","content":{"appearanceInfo":{"pippitAssetId":"image-material"}}}`)}},
58
+ {"root-replace", blank, []PatchEntry{bindingPatch("replace", "", `{"type":"biz/image","content":{"sourceInfos":{"image-material":{}}}}`)}},
59
+ {"content-replace", blank, []PatchEntry{bindingPatch("replace", "/content", `{"appearanceInfo":{"candidateId":"candidate"}}`)}},
60
+ {"nested-appearance", `{"type":"biz/image","content":{"appearanceInfo":{}}}`, []PatchEntry{bindingPatch("add", "/content/appearanceInfo/pippitAssetId", `"image-material"`)}},
61
+ {"nested-source-map", `{"type":"biz/image","content":{"sourceInfos":{}}}`, []PatchEntry{bindingPatch("add", "/content/sourceInfos/material", `{"pippitAssetId":"image-material"}`)}},
62
+ {"nested-source-array", `{"type":"biz/image","content":{"sourceInfos":[]}}`, []PatchEntry{bindingPatch("add", "/content/sourceInfos/-", `{"pippitAssetId":"image-material"}`)}},
63
+ {"changed-legacy-field", `{"type":"biz/image","content":{"appearanceInfo":{"pippitAssetId":"old"}}}`, []PatchEntry{bindingPatch("replace", "/content/appearanceInfo/pippitAssetId", `"new"`)}},
64
+ {"remove-one-legacy-source", `{"type":"biz/image","content":{"sourceInfos":{"first":{},"second":{}}}}`, []PatchEntry{bindingPatch("remove", "/content/sourceInfos/first", "")}},
65
+ {"unchanged-direct-identities", string(imageNode(testMediaID)), []PatchEntry{bindingPatch("add", "/content/sourceInfos", `{"material":{}}`)}},
66
+ {"type-change", `{"type":"biz/role","content":{"appearanceInfo":{"pippitAssetId":"material"}}}`, []PatchEntry{bindingPatch("replace", "/type", `"biz/image"`)}},
67
+ {"case-alias", blank, []PatchEntry{bindingPatch("add", "/content/AppearanceInfo", `{"pippitAssetId":"material"}`)}},
68
+ } {
69
+ t.Run(test.name, func(t *testing.T) {
70
+ opts, runner, writes := imageBindingFixture(test.node, test.patches)
71
+ _, err := Apply(context.Background(), opts, runner)
72
+ if err == nil || !strings.Contains(err.Error(), "INVALID_MEDIA_IDENTITY") || !strings.Contains(err.Error(), "/content/") || !strings.Contains(err.Error(), "content.pippitAssetId") {
73
+ t.Fatalf("expected corrective image binding error, got %v", err)
74
+ }
75
+ if *writes != 0 {
76
+ t.Fatalf("invalid image binding was sent %d times", *writes)
77
+ }
78
+ })
79
+ }
80
+ }
81
+
82
+ func TestApplyMediaIdentityPreservesImageDraftAndLegacyEdits(t *testing.T) {
83
+ legacy := `{"type":"biz/image","content":{"caption":"old","appearanceInfo":{"pippitAssetId":"material","candidateId":"candidate"},"sourceInfos":{"material":{}}}}`
84
+ for _, test := range []struct {
85
+ name, node string
86
+ patches []PatchEntry
87
+ }{
88
+ {"blank-create", "", []PatchEntry{bindingPatch("add", "", `{"type":"biz/image","content":{"caption":"draft"}}`)}},
89
+ {"legacy-caption", legacy, []PatchEntry{bindingPatch("replace", "/content/caption", `"edited"`)}},
90
+ {"unchanged-content", legacy, []PatchEntry{bindingPatch("replace", "/content", `{"sourceInfos":{"material":{}},"appearanceInfo":{"candidateId":"candidate","pippitAssetId":"material"},"caption":"edited"}`)}},
91
+ {"unchanged-root", legacy, []PatchEntry{bindingPatch("replace", "", `{"type":"biz/image","content":{"sourceInfos":{"material":{}},"appearanceInfo":{"candidateId":"candidate","pippitAssetId":"material"},"caption":"edited"}}`)}},
92
+ {"unchanged-nested-field", legacy, []PatchEntry{bindingPatch("replace", "/content/appearanceInfo/pippitAssetId", `"material"`)}},
93
+ {"remove-field", legacy, []PatchEntry{bindingPatch("remove", "/content/appearanceInfo", "")}},
94
+ {"clear-object", legacy, []PatchEntry{bindingPatch("replace", "/content/appearanceInfo", `{}`)}},
95
+ {"clear-array", legacy, []PatchEntry{bindingPatch("replace", "/content/sourceInfos", `[]`)}},
96
+ {"clear-null", legacy, []PatchEntry{bindingPatch("replace", "/content/sourceInfos", `null`)}},
97
+ {"clear-blank", legacy, []PatchEntry{bindingPatch("replace", "/content/appearanceInfo", `" "`)}},
98
+ {"clear-last-object-key", `{"type":"biz/image","content":{"sourceInfos":{"a/b~c":{}}}}`, []PatchEntry{bindingPatch("remove", "/content/sourceInfos/a~1b~0c", "")}},
99
+ {"clear-last-array-item", `{"type":"biz/image","content":{"sourceInfos":[{"pippitAssetId":"material"}]}}`, []PatchEntry{bindingPatch("remove", "/content/sourceInfos/0", "")}},
100
+ {"final-role-type", `{"type":"biz/image","content":{}}`, []PatchEntry{
101
+ bindingPatch("add", "/content/appearanceInfo", `{"pippitAssetId":"material"}`),
102
+ bindingPatch("replace", "/type", `"biz/role"`),
103
+ }},
104
+ {"final-empty-binding", `{"type":"biz/image","content":{}}`, []PatchEntry{
105
+ bindingPatch("add", "/content/appearanceInfo", `{"pippitAssetId":"material"}`),
106
+ bindingPatch("remove", "/content/appearanceInfo", ""),
107
+ }},
108
+ } {
109
+ t.Run(test.name, func(t *testing.T) {
110
+ opts, runner, writes := imageBindingFixture(test.node, test.patches)
111
+ if _, err := Apply(context.Background(), opts, runner); err != nil {
112
+ t.Fatal(err)
113
+ }
114
+ if *writes != 1 {
115
+ t.Fatalf("writes = %d", *writes)
116
+ }
117
+ })
118
+ }
119
+ }
120
+
121
+ func TestApplyMediaIdentityLeavesOtherNodeBindingsUnchanged(t *testing.T) {
122
+ for _, kind := range []string{"role", "scene", "audio", "video"} {
123
+ t.Run(kind, func(t *testing.T) {
124
+ node := fmt.Sprintf(`{"type":"biz/%s","content":{"appearanceInfo":{},"sourceInfos":[]}}`, kind)
125
+ opts, runner, writes := imageBindingFixture(node, []PatchEntry{
126
+ bindingPatch("add", "/content/appearanceInfo/pippitAssetId", `"material"`),
127
+ bindingPatch("add", "/content/sourceInfos/-", `{"pippitAssetId":"material"}`),
128
+ })
129
+ if _, err := Apply(context.Background(), opts, runner); err != nil {
130
+ t.Fatal(err)
131
+ }
132
+ if *writes != 1 {
133
+ t.Fatalf("writes = %d", *writes)
134
+ }
135
+ })
136
+ }
137
+ }
@@ -4,6 +4,7 @@ import (
4
4
  "context"
5
5
  "encoding/json"
6
6
  "fmt"
7
+ "maps"
7
8
  "strings"
8
9
 
9
10
  "github.com/Pippit-dev/pippit-cli/internal/common"
@@ -91,10 +92,17 @@ func cloudMediaID(raw json.RawMessage, kind string) (string, error) {
91
92
  }
92
93
 
93
94
  func touchesMediaIdentity(path string) bool {
94
- switch strings.ToLower(path) {
95
+ normalized := strings.ToLower(path)
96
+ switch normalized {
95
97
  case "", "/type", "/content", "/content/assetid", "/content/pippitassetid":
96
98
  return true
97
99
  }
100
+ for _, field := range imageSubjectFields {
101
+ prefix := "/content/" + field
102
+ if normalized == prefix || strings.HasPrefix(normalized, prefix+"/") {
103
+ return true
104
+ }
105
+ }
98
106
  return false
99
107
  }
100
108
 
@@ -143,6 +151,9 @@ func projectIdentityPatch(node map[string]json.RawMessage, patch PatchEntry) (ma
143
151
  return nil, fmt.Errorf("cannot validate a patch without its node base")
144
152
  }
145
153
  parts := strings.Split(strings.TrimPrefix(patch.Path, "/"), "/")
154
+ for index, part := range parts {
155
+ parts[index] = strings.NewReplacer("~1", "/", "~0", "~").Replace(part)
156
+ }
146
157
  key := parts[0]
147
158
  if len(parts) == 1 {
148
159
  if patch.Op == "remove" {
@@ -152,16 +163,7 @@ func projectIdentityPatch(node map[string]json.RawMessage, patch PatchEntry) (ma
152
163
  }
153
164
  return node, nil
154
165
  }
155
- var content map[string]json.RawMessage
156
- if err := json.Unmarshal(node[key], &content); err != nil || content == nil {
157
- return nil, fmt.Errorf("cannot validate a media identity without its content base")
158
- }
159
- if patch.Op == "remove" {
160
- delete(content, parts[1])
161
- } else {
162
- content[parts[1]] = patch.Value
163
- }
164
- value, err := json.Marshal(content)
166
+ value, err := projectMediaIdentityValue(node[key], parts[1:], patch)
165
167
  if err != nil {
166
168
  return nil, err
167
169
  }
@@ -210,12 +212,13 @@ func validateApplyMediaIdentities(ctx context.Context, request ApplyRequest, run
210
212
  if touchesMediaIdentity(patch.Path) && !affected[patch.AssetID] {
211
213
  affected[patch.AssetID] = true
212
214
  ordered = append(ordered, patch.AssetID)
213
- if patch.Path != "" {
215
+ if patch.Path != "" || replacesImageSubjectBinding(patch) {
214
216
  toQuery = append(toQuery, patch.AssetID)
215
217
  }
216
218
  }
217
219
  }
218
220
  nodes := make(map[string]map[string]json.RawMessage)
221
+ previousNodes := make(map[string]map[string]json.RawMessage)
219
222
  type identity struct{ nodeID, kind, pippitID, mediaID string }
220
223
  previous := make(map[string]identity)
221
224
  if len(toQuery) > 0 {
@@ -230,6 +233,7 @@ func validateApplyMediaIdentities(ctx context.Context, request ApplyRequest, run
230
233
  return mediaIdentityError(id, "/content", err.Error())
231
234
  }
232
235
  nodes[id] = node
236
+ previousNodes[id] = maps.Clone(node)
233
237
  kind, pippitID, mediaID, readErr := readNodeIdentity(node)
234
238
  if readErr == nil {
235
239
  previous[id] = identity{id, kind, pippitID, mediaID}
@@ -254,6 +258,11 @@ func validateApplyMediaIdentities(ctx context.Context, request ApplyRequest, run
254
258
  if err != nil {
255
259
  return mediaIdentityError(nodeID, "/content", err.Error())
256
260
  }
261
+ if kind == "image" {
262
+ if err := validateImageSubjectBinding(nodeID, nodes[nodeID], previousNodes[nodeID]); err != nil {
263
+ return err
264
+ }
265
+ }
257
266
  if kind == "" || (pippitID == "" && mediaID == "") {
258
267
  continue
259
268
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pippit-dev/cli",
3
- "version": "1.0.49",
3
+ "version": "1.0.51",
4
4
  "description": "Pippit CLI",
5
5
  "bin": {
6
6
  "pippit-tool-cli": "scripts/run.js"