feat(asset-ai): add contextual analysis and unmet-demand feedback

This commit is contained in:
shishengliang
2026-09-23 16:01:10 +08:00
parent 0a32392215
commit 7e9760f5db
23 changed files with 5160 additions and 835 deletions
@@ -0,0 +1,26 @@
import assert from "node:assert/strict";
import test from "node:test";
import pool from "../../db.js";
import { gapStore } from "./gaps.js";
test("demand storage reuses a precreated table, deduplicates, binds ownership and purges expired records", async (t) => {
const calls: { sql: string; params: unknown[] }[] = [];
t.mock.method(pool, "query", async (sql: string, params: unknown[] = []) => {
calls.push({ sql, params });
return [[], []];
});
await gapStore.record("user-A", "预测 库存", "unsupported");
await gapStore.record("user-A", "预测 库存", "unsupported");
const writes = calls.filter((c) => c.sql.includes("INSERT INTO"));
assert.equal(writes.length, 2);
assert.deepEqual(writes[0].params, writes[1].params);
assert.match(writes[0].sql, /ON DUPLICATE KEY UPDATE/);
assert.match(writes[0].sql, /status='resolved'/);
assert.ok(!calls.some((c) => c.sql.includes("CREATE TABLE")));
await gapStore.list("user-A");
const list = calls.find((c) => c.sql.includes("ORDER BY"))!;
assert.match(list.sql, /WHERE user_id = \?/);
assert.deepEqual(list.params, ["user-A"]);
assert.ok(calls.some((c) => c.sql.includes("INTERVAL 90 DAY")));
await gapStore.update(1, "planned");
assert.deepEqual(calls.at(-1)?.params, ["planned", 1]);
});