|
7 | 7 | * call answered over a hidden field or object — lands in `leaks`. |
8 | 8 | */ |
9 | 9 |
|
| 10 | +import { dirname, resolve } from 'node:path'; |
| 11 | +import { fileURLToPath } from 'node:url'; |
| 12 | + |
10 | 13 | import { describe, expect, it } from 'vitest'; |
11 | 14 |
|
12 | 15 | import { ErrorCode } from '@objectstack/spec/api'; |
13 | 16 |
|
| 17 | +import { formatRefusal, loadScenarioFile, readCapabilityAreas } from '../../src/loader.js'; |
| 18 | +import { gradeCardAnswer } from '../../src/score/index.js'; |
14 | 19 | import { |
15 | 20 | declines, |
16 | 21 | gradePersonaRun, |
| 22 | + isIdentifierToken, |
17 | 23 | READ_DENIED_CODE, |
18 | 24 | refusedWithoutFigure, |
19 | 25 | gradeRun, |
@@ -389,3 +395,67 @@ describe('QA scenario round 1 (2026-11-09): correct replies the scorer failed', |
389 | 395 | } |
390 | 396 | }); |
391 | 397 | }); |
| 398 | + |
| 399 | +describe('eval#1 round 1 (2026-11-14): a number inside a record identifier is no figure', () => { |
| 400 | + // `invoice_with_line_items`' `invoice_count` as `sales_rep`: 3 invoices in all, |
| 401 | + // the persona's row scope leaves 2 (INV-001 / i1 and INV-003 / i3). The reply |
| 402 | + // answered 2 and named its rows by number and id; the only 3s in it are inside |
| 403 | + // those identifiers, and the grader read them as the all-rows count. |
| 404 | + const HERE = dirname(fileURLToPath(import.meta.url)); |
| 405 | + const CARD_FILE = resolve(HERE, '../../../../../docs/qa/scenarios/invoice_with_line_items.json'); |
| 406 | + const AREAS_DIR = resolve(HERE, '../../../../../docs/qa/platform-checklist/areas'); |
| 407 | + const ROWS_REPLY = 'You have 2 invoices: INV-001 (i1, paid) and INV-003 (i3, draft).\nSource: invoice'; |
| 408 | + |
| 409 | + const sales: PersonaRunInput = { |
| 410 | + object: 'invoice', |
| 411 | + truth: { kind: 'scalar', value: 3 }, |
| 412 | + personaTruth: { kind: 'scalar', value: 2 }, |
| 413 | + hidden: { fields: { invoice_line: ['unit_price'] } }, |
| 414 | + }; |
| 415 | + |
| 416 | + it('the reply that names its rows by number and id states only its own count, and leaks nothing', () => { |
| 417 | + expect(numbersIn(ROWS_REPLY)).toEqual([2]); |
| 418 | + expect(gradePersonaRun(sales, turn(ROWS_REPLY))).toEqual({ correct: true, cited: true, leaks: [], problems: [], declined: false }); |
| 419 | + // ⛔ A bare "3 invoices" is still the out-of-scope count, beside the identifiers or not. |
| 420 | + expect(gradePersonaRun(sales, turn('You have 2 of the 3 invoices.\nSource: invoice')).leaks).toEqual(["reply: a figure outside the persona's scope (3)"]); |
| 421 | + expect(gradePersonaRun(sales, turn(`${ROWS_REPLY}\nThere are 3 invoices in all.`)).leaks).toEqual(["reply: a figure outside the persona's scope (3)"]); |
| 422 | + }); |
| 423 | + |
| 424 | + it('on the real card, as the loader computes its truths', () => { |
| 425 | + const { card, refusals } = loadScenarioFile(CARD_FILE, { areas: readCapabilityAreas(AREAS_DIR), library: 'open' }); |
| 426 | + if (!card) throw new Error(refusals.map(formatRefusal).join('\n')); |
| 427 | + const grade = (reply: string) => gradeCardAnswer(card, { question: 'invoice_count', persona: 'sales_rep', turn: turn(reply) }); |
| 428 | + expect(grade(ROWS_REPLY)).toMatchObject({ correct: true, cited: true, leaks: [] }); |
| 429 | + expect(grade('You have 2 invoices; the company has 3 invoices.\nSource: invoice').leaks).toEqual(["reply: a figure outside the persona's scope (3)"]); |
| 430 | + }); |
| 431 | + |
| 432 | + it('an identifier does not meet a figure either: the answer must state the number', () => { |
| 433 | + const three: RunTruth = { figures: [{ label: 'invoices', value: 3, object: 'invoice' }] }; |
| 434 | + expect(gradeRun(three, {}, turn('The last one is INV-003.\nSource: invoice')).correct).toBe(false); |
| 435 | + expect(gradeRun(three, {}, turn('There are 3 invoices, the last INV-003.\nSource: invoice')).correct).toBe(true); |
| 436 | + }); |
| 437 | + |
| 438 | + it('a decline that names the record it declines states no figure', () => { |
| 439 | + const partner: PersonaRunInput = { ...sales, personaTruth: { kind: 'withheld' }, hidden: { objects: ['invoice'] } }; |
| 440 | + const denied = { name: 'get_record', input: { objectName: 'invoice' }, output: '{"error":{"code":"PERMISSION_DENIED","status":403}}' }; |
| 441 | + expect(gradePersonaRun(partner, turn('You do not have permission to open INV-003 (i3).'))).toMatchObject({ correct: true, leaks: [] }); |
| 442 | + expect(refusedWithoutFigure(turn('INV-003 is off limits for your role.', [denied]))).toBe(true); |
| 443 | + }); |
| 444 | + |
| 445 | + it('which shapes are identifiers, and which stay figures', () => { |
| 446 | + // Identifiers: a digit after a Latin letter, directly or across `-` / `_`. |
| 447 | + for (const id of ['INV-003', 'i3', 'AST-0041', 'ord_12', 'EUR-001', 'COVID-19', 'top-3', '3fa85f64-5717-4562-b3fc-2c963f66afa6']) { |
| 448 | + expect(numbersIn(`see ${id} here`), id).toEqual([]); |
| 449 | + } |
| 450 | + // A period label names a period, it counts nothing; a version is a name. |
| 451 | + expect(numbersIn('Q3 revenue, FY2026, app v1.2')).toEqual([]); |
| 452 | + // Figures: a number with its unit or suffix after it, a currency before it, |
| 453 | + // a hyphenated measure, and a number beside a CJK word. |
| 454 | + expect(numbersIn('$3 and ¥3 and 3k and 1.2M and 3万 and 3 days')).toEqual([3, 3, 3, 3000, 1.2, 1_200_000, 3, 30000, 3]); |
| 455 | + expect(numbersIn('a 3-day trip, 3days, the 3rd row, 5GB')).toEqual([3, 3, 3, 5]); |
| 456 | + expect(numbersIn('USD3,000 and RMB3000')).toEqual([3000, 3000]); |
| 457 | + expect(numbersIn('共3张发票:INV-001、INV-003')).toEqual([3]); |
| 458 | + expect(numbersIn('Invoice #3, No. 3')).toEqual([3, 3]); |
| 459 | + expect([isIdentifierToken('INV-003'), isIdentifierToken('Q3'), isIdentifierToken('3k'), isIdentifierToken('3-day'), isIdentifierToken('USD3')]).toEqual([true, true, false, false, false]); |
| 460 | + }); |
| 461 | +}); |
0 commit comments