chore: import upstream snapshot with attribution
CI / license-header (push) Has been skipped
CI / e2e-dry-run (push) Has been skipped
CI / fast-gate (push) Failing after 0s
Test PR Label Logic / test-pr-labels (push) Failing after 1s
Skill Format Check / check-format (push) Failing after 2s
CI / security (push) Failing after 5s
CI / unit-test (push) Has been skipped
CI / lint (push) Has been skipped
CI / script-test (push) Has been skipped
CI / deterministic-gate (push) Has been skipped
CI / coverage (push) Has been skipped
CI / results (push) Has been cancelled
CI / deadcode (push) Has been cancelled
CI / e2e-live (push) Has been cancelled
CI / license-header (push) Has been skipped
CI / e2e-dry-run (push) Has been skipped
CI / fast-gate (push) Failing after 0s
Test PR Label Logic / test-pr-labels (push) Failing after 1s
Skill Format Check / check-format (push) Failing after 2s
CI / security (push) Failing after 5s
CI / unit-test (push) Has been skipped
CI / lint (push) Has been skipped
CI / script-test (push) Has been skipped
CI / deterministic-gate (push) Has been skipped
CI / coverage (push) Has been skipped
CI / results (push) Has been cancelled
CI / deadcode (push) Has been cancelled
CI / e2e-live (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
// Copyright (c) 2026 Lark Technologies Pte. Ltd.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
const { classifyIssueText } = require("./index.js");
|
||||
|
||||
const samplesPath = path.join(__dirname, "samples.json");
|
||||
const samples = JSON.parse(fs.readFileSync(samplesPath, "utf8"));
|
||||
|
||||
/**
|
||||
* Convert an array-like value into a sorted string array.
|
||||
*
|
||||
* @param {Array<unknown>|undefined|null} arr
|
||||
* @returns {string[]}
|
||||
*/
|
||||
function sortArray(arr) {
|
||||
return (arr || []).map(String).sort();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether every element in sub exists in sup.
|
||||
*
|
||||
* @param {string[]} sub
|
||||
* @param {string[]} sup
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function isSubset(sub, sup) {
|
||||
const set = new Set(sup || []);
|
||||
for (const x of sub || []) {
|
||||
if (!set.has(x)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
let passed = 0;
|
||||
let failed = 0;
|
||||
|
||||
for (const sample of samples) {
|
||||
try {
|
||||
const result = classifyIssueText(sample.title, sample.body);
|
||||
|
||||
const hasExpectedType = Object.prototype.hasOwnProperty.call(sample, "expected_type");
|
||||
const expectedType = hasExpectedType ? sample.expected_type : undefined;
|
||||
const matchType = hasExpectedType ? (result.type || null) === expectedType : true;
|
||||
const actualDomains = sortArray(result.domains);
|
||||
const expectedDomains = sortArray(sample.expected_domains);
|
||||
const hasExpectedDomains = Object.prototype.hasOwnProperty.call(sample, "expected_domains");
|
||||
const matchDomains = !hasExpectedDomains
|
||||
? true
|
||||
: expectedDomains.length === 0
|
||||
? actualDomains.length === 0
|
||||
: isSubset(expectedDomains, actualDomains);
|
||||
|
||||
if (matchType && matchDomains) {
|
||||
console.log(`✅ Passed: ${sample.name}`);
|
||||
passed += 1;
|
||||
} else {
|
||||
console.log(`❌ Failed: ${sample.name}`);
|
||||
console.log(` Type expected: ${expectedType}, got: ${result.type}`);
|
||||
console.log(` Domains expected(subset): ${expectedDomains}, got: ${actualDomains}`);
|
||||
failed += 1;
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(`❌ Failed: ${sample.name} (Execution error)`);
|
||||
console.error(e && e.message ? e.message : String(e));
|
||||
failed += 1;
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`\nTest Summary: ${passed} passed, ${failed} failed`);
|
||||
if (failed > 0) process.exit(1);
|
||||
Reference in New Issue
Block a user