initial commit
This commit is contained in:
69
test/llmParameterExtractor.test.js
Normal file
69
test/llmParameterExtractor.test.js
Normal file
@@ -0,0 +1,69 @@
|
||||
"use strict";
|
||||
|
||||
const test = require("node:test");
|
||||
const assert = require("node:assert/strict");
|
||||
const { extractFlightSearchRequest } = require("../src/llmParameterExtractor");
|
||||
|
||||
test("uses LLM output when client is provided", async () => {
|
||||
const llmClient = async () => ({
|
||||
departureDateWindow: {
|
||||
from: "2026-11-21",
|
||||
to: "2026-12-10",
|
||||
},
|
||||
stayDurationDays: {
|
||||
minDays: 12,
|
||||
maxDays: 14,
|
||||
},
|
||||
segments: [
|
||||
{ from: "ICN", to: "MAD" },
|
||||
{ from: "MAD", to: "ICN" },
|
||||
],
|
||||
passengers: {
|
||||
total: 2,
|
||||
byCabin: {
|
||||
economy: 0,
|
||||
premium_economy: 0,
|
||||
business: 2,
|
||||
first: 0,
|
||||
},
|
||||
},
|
||||
constraints: {
|
||||
sameFlightForAllPassengers: true,
|
||||
itineraryCount: 1,
|
||||
maxStops: 0,
|
||||
maxJourneyHours: {
|
||||
hours: 20,
|
||||
operator: "<=",
|
||||
},
|
||||
},
|
||||
tripType: "round_trip",
|
||||
warnings: [],
|
||||
missingFields: [],
|
||||
});
|
||||
|
||||
const result = await extractFlightSearchRequest("임의 입력", {
|
||||
now: new Date("2026-02-19T00:00:00Z"),
|
||||
llmClient,
|
||||
});
|
||||
|
||||
assert.equal(result.source, "llm");
|
||||
assert.equal(result.params.tripType, "round_trip");
|
||||
assert.equal(result.params.departureDateWindow.from, "2026-11-21");
|
||||
assert.equal(result.params.constraints.maxJourneyHours.hours, 20);
|
||||
assert.deepEqual(result.params.missingFields, []);
|
||||
});
|
||||
|
||||
test("falls back to rule parser when LLM client fails", async () => {
|
||||
const result = await extractFlightSearchRequest("인천->마드리드 20시간 이하", {
|
||||
llmClient: async () => {
|
||||
throw new Error("intentional failure");
|
||||
},
|
||||
});
|
||||
|
||||
assert.equal(result.source, "rule_parser");
|
||||
assert.equal(result.params.constraints.maxJourneyHours.hours, 20);
|
||||
assert.equal(
|
||||
result.params.warnings.some((warning) => warning.includes("LLM extraction fallback triggered")),
|
||||
true
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user