feat(asset-ai): add contextual analysis and unmet-demand feedback
This commit is contained in:
@@ -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]);
|
||||
});
|
||||
Reference in New Issue
Block a user