Skip to content

DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.

fix(pets): 导入不再拒绝未知 kind 的 Codex 图集宠物 (#1099)

Hairy062094019cde
diff --git a/packages/dsh-tauri-pet/skills/hatch-dsh-pet/references/validate-pet.mjs b/packages/dsh-tauri-pet/skills/hatch-dsh-pet/references/validate-pet.mjs
index ee8cc864..728edf56 100644
--- a/packages/dsh-tauri-pet/skills/hatch-dsh-pet/references/validate-pet.mjs
+++ b/packages/dsh-tauri-pet/skills/hatch-dsh-pet/references/validate-pet.mjs
@@ -356,7 +356,7 @@ function main() {
}
checkId(manifest.id)
- for (const field of ['displayName', 'description']) {
+ for (const field of ['displayName', 'description', 'kind']) {
if (manifest[field] !== undefined && manifest[field] !== null && typeof manifest[field] !== 'string')
fail(`PET_MANIFEST_INVALID: ${field} must be a string`)
}
@@ -366,8 +366,6 @@ function main() {
report()
return
}
- if (manifest.kind !== undefined && manifest.kind !== 'codex')
- fail('PET_MANIFEST_INVALID: kind must be dsh or codex')
let declared
if (manifest.spriteVersionNumber !== undefined && manifest.spriteVersionNumber !== null) {
diff --git a/packages/dsh-tauri-pet/skills/hatch-dsh-pet/references/validate-pet.test.mjs b/packages/dsh-tauri-pet/skills/hatch-dsh-pet/references/validate-pet.test.mjs
index af38be43..de533b18 100644
--- a/packages/dsh-tauri-pet/skills/hatch-dsh-pet/references/validate-pet.test.mjs
+++ b/packages/dsh-tauri-pet/skills/hatch-dsh-pet/references/validate-pet.test.mjs
@@ -25,6 +25,18 @@ function validate() {
return spawnSync(process.execPath, [validator, root], { encoding: 'utf8', timeout: 5000 })
}
+function webpAtlas(width = 88, height = 88) {
+ const bytes = Buffer.alloc(30)
+ bytes.write('RIFF', 0, 'ascii')
+ bytes.writeUInt32LE(22, 4)
+ bytes.write('WEBP', 8, 'ascii')
+ bytes.write('VP8X', 12, 'ascii')
+ bytes.writeUInt32LE(10, 16)
+ bytes.writeUIntLE(width - 1, 24, 3)
+ bytes.writeUIntLE(height - 1, 27, 3)
+ return bytes
+}
+
it('accepts a local WebM package with JSONC and a square GIF without claiming decoded playback', () => {
const result = validate()
expect(result.status).toBe(0)
@@ -45,3 +57,21 @@ it('rejects missing referenced video files', () => {
expect(result.status).toBe(1)
expect(result.stderr).toContain('PET_ASSET_READ_FAILED: video missing')
})
+
+it('accepts a Codex atlas manifest whose kind uses a foreign vocabulary', () => {
+ // 外部生态用 kind 标注宠物类别(如 person/pet),图集导入只看 spritesheetPath,
+ // 白名单会把这类宠物误判为非法清单。
+ manifest = { kind: 'person', id: 'fixture', spriteVersionNumber: 2, spritesheetPath: 'spritesheet.webp' }
+ writeFileSync(join(root, 'spritesheet.webp'), webpAtlas())
+ const result = validate()
+ expect(result.status).toBe(0)
+ expect(result.stdout).toContain('atlas image/webp 88x88 -> v2 8x11')
+})
+
+it.each([{ kind: false }, { kind: 1 }, { kind: {} }, { kind: [] }])('rejects a non-string kind $kind like the Rust importer', ({ kind }) => {
+ manifest = { kind, id: 'fixture', spritesheetPath: 'spritesheet.webp' }
+ writeFileSync(join(root, 'spritesheet.webp'), webpAtlas())
+ const result = validate()
+ expect(result.status).toBe(1)
+ expect(result.stderr).toContain('PET_MANIFEST_INVALID: kind must be a string')
+})
diff --git a/src-tauri/src/bridge/pet.rs b/src-tauri/src/bridge/pet.rs
index 53f46a0a..4ca5fa8e 100644
--- a/src-tauri/src/bridge/pet.rs
+++ b/src-tauri/src/bridge/pet.rs
@@ -855,9 +855,6 @@ fn parse_manifest_bytes(bytes: &[u8]) -> Result<PetManifest, String> {
}
}
match manifest.kind.as_deref() {
- None | Some("codex") => {
- safe_relative_path(&manifest.spritesheet_path)?;
- }
Some("dsh") => {
for path in [
manifest.config_path.as_deref(),
@@ -895,7 +892,10 @@ fn parse_manifest_bytes(bytes: &[u8]) -> Result<PetManifest, String> {
return Err("PET_MANIFEST_INVALID: size must be within 0..=4096".to_string());
}
}
- _ => return Err("PET_MANIFEST_INVALID: kind must be dsh or codex".to_string()),
+ // 图集宠物不认 `kind`:外部生态用它标注宠物类别(如 person/pet),只以 `spritesheetPath` 为准。
+ _ => {
+ safe_relative_path(&manifest.spritesheet_path)?;
+ }
}
Ok(manifest)
}
@@ -2756,6 +2756,34 @@ mod tests {
assert!(!directory.0.join("wrapper").exists());
}
+ #[test]
+ fn extraction_accepts_codex_manifest_with_unrecognized_kind() {
+ // 外部生成的 Codex 宠物会用 `kind` 标注自己的类别(如 person/pet),导入只认图集路径,
+ // 新增的白名单把这些宠物全部挡在门外。
+ let manifest = br#"{"id":"ene","kind":"person","spriteVersionNumber":2,"spritesheetPath":"spritesheet.webp"}"#;
+ let webp = valid_test_webp();
+ let archive = build_archive(&[
+ ("ene.codex-pet/pet.json", manifest),
+ ("ene.codex-pet/spritesheet.webp", &webp),
+ ]);
+ let directory = TestDirectory::new("unknown-kind");
+ let parsed = extract_pet_archive(&archive, &directory.0).unwrap();
+ assert_eq!(parsed.id, "ene");
+ assert_eq!(parsed.kind.as_deref(), Some("person"));
+
+ let installed = read_manifest(&directory.0).unwrap();
+ validate_pet_source(PetSource::Codex, &installed).unwrap();
+ let item = manifest_to_list_item(PetSource::Codex, &directory.0, installed);
+ assert_eq!(item.id, "codex:ene");
+ assert_eq!(item.source, "codex");
+ assert_eq!(item.kind, "codex");
+ assert_eq!(item.thumbnail_type, "spritesheet");
+ assert!(item
+ .thumbnail
+ .unwrap()
+ .starts_with("data:image/webp;base64,"));
+ }
+
#[test]
fn extraction_accepts_macos_finder_archive_with_v1_atlas() {
// issue #559:Finder/ditto 生成的 zip 会带上 `__MACOSX` 资源叉与 `.DS_Store`,