WuYongJie 1b6425b552 feat(desktop): connect native Pi sessions with scoped rules and recovery
Track the fixed PhotoCraft source baseline with the existing native client integration. Use the actual Pi SDK for normal sends, durable session recovery, demand-loaded enterprise rules and checked undoable canvas tools. Retain request identities and never resend unknown inference. Include local packaging and real-call acceptance evidence.
2026-10-22 10:49:58 +08:00

20 lines
1.7 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import { resolveRules } from '../src/rules.mjs';
const catalog = () => ({
brands: [{ id: 'brand', name: 'QA', revision: 'v1', source: 'qa', profile: { tone: '克制', fontFamily: 'Noto Sans SC', visualRules: { palette: '暖色' } } }],
shops: [{ id: 'A', brandId: 'brand', revision: 's1', source: 'qa-fixture', platform: 'qa', rules: ['A店规则'] }, { id: 'B', brandId: 'brand', revision: 's2', source: 'qa-fixture', platform: 'qa', rules: ['B店规则'] }],
categories: [{ id: 'desk', revision: 'c1', source: 'qa-fixture', rules: ['书桌'] }, { id: 'chair', revision: 'c2', source: 'qa-fixture', rules: ['餐椅'] }],
bindings: [{ id: 'A-desk', shopId: 'A', categoryId: 'desk', revision: 'b1', source: 'qa-fixture', state: 'ready', rules: ['组合A'] }, { id: 'B-chair', shopId: 'B', categoryId: 'chair', revision: 'b2', source: 'qa-fixture', state: 'ready', rules: ['组合B'] }],
});
test('brand/shop/category rules resolve exactly and missing combinations fail closed', () => {
const c = catalog(), a = resolveRules({ brandId: 'brand', shopId: 'A', categoryId: 'desk' }, c);
assert.ok(a.rules.includes('A店规则')); assert.ok(!a.rules.includes('B店规则'));
const b = resolveRules({ brandId: 'brand', shopId: 'B', categoryId: 'chair' }, c);
assert.notEqual(a.version, b.version);
assert.throws(() => resolveRules({ brandId: 'brand', shopId: 'A', categoryId: 'chair' }, c), /尚未配置/);
c.brands[0].revision = 'v2'; c.brands[0].profile = { ...c.brands[0].profile, tone: '新规则' };
assert.equal(a.brandSnapshot.tone, '克制');
assert.notEqual(resolveRules({ brandId: 'brand', shopId: 'A', categoryId: 'desk' }, c).version, a.version);
});