Update hivegrid-cloud reference to latest main
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e98d38e716
commit
7b21524c86
3781 files changed
+373484
-225607
No files matched your search
@@ -0,0 +1,140 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { createValidationReport, detectDuplicateRows } from "./dedupe.js";
|
||||
import type { ImportRowResult } from "./index.js";
|
||||
|
||||
describe("duplicate detection edge cases", () => {
|
||||
it("builds composite keys from array values, stripping blank and null items", () => {
|
||||
const report = detectDuplicateRows(
|
||||
[
|
||||
{ rowNumber: 1, normalized: { ids: [1, "a", null, " "] } },
|
||||
{ rowNumber: 2, normalized: { ids: ["1", "a"] } },
|
||||
{ rowNumber: 3, normalized: { ids: ["a", "1"] } },
|
||||
],
|
||||
["ids"],
|
||||
);
|
||||
|
||||
// Rows 1 and 2 normalize to the same ["1","a"] signature (numeric 1 -> "1", blanks dropped);
|
||||
// row 3 differs because element order changes the JSON signature.
|
||||
expect(report.groups).toEqual([
|
||||
{
|
||||
id: "duplicate-group-0001",
|
||||
key: [{ field: "ids", valuePreview: '["1","a"]' }],
|
||||
rowNumbers: [1, 2],
|
||||
},
|
||||
]);
|
||||
expect(report.summary).toMatchObject({ totalRows: 3, duplicateGroups: 1, duplicateRows: 2 });
|
||||
});
|
||||
|
||||
it("skips rows whose only key field is an all-blank array", () => {
|
||||
const report = detectDuplicateRows(
|
||||
[
|
||||
{ rowNumber: 1, normalized: { ids: [null, " "] } },
|
||||
{ rowNumber: 2, normalized: { ids: [] } },
|
||||
],
|
||||
["ids"],
|
||||
);
|
||||
|
||||
expect(report.groups).toEqual([]);
|
||||
expect(report.summary).toMatchObject({ totalRows: 2, duplicateGroups: 0, duplicateRows: 0 });
|
||||
expect(report.rowResults.every((row) => row.ok)).toBe(true);
|
||||
});
|
||||
|
||||
it("stringifies numeric and boolean scalar key values", () => {
|
||||
const numericReport = detectDuplicateRows(
|
||||
[
|
||||
{ rowNumber: 1, normalized: { score: 42 } },
|
||||
{ rowNumber: 2, normalized: { score: 42 } },
|
||||
{ rowNumber: 3, normalized: { score: 7 } },
|
||||
],
|
||||
["score"],
|
||||
);
|
||||
expect(numericReport.groups).toEqual([
|
||||
{ id: "duplicate-group-0001", key: [{ field: "score", valuePreview: "42" }], rowNumbers: [1, 2] },
|
||||
]);
|
||||
|
||||
const booleanReport = detectDuplicateRows(
|
||||
[
|
||||
{ rowNumber: 1, normalized: { active: true } },
|
||||
{ rowNumber: 2, normalized: { active: true } },
|
||||
],
|
||||
["active"],
|
||||
);
|
||||
expect(booleanReport.groups).toEqual([
|
||||
{ id: "duplicate-group-0001", key: [{ field: "active", valuePreview: "true" }], rowNumbers: [1, 2] },
|
||||
]);
|
||||
});
|
||||
|
||||
it("accepts DuplicateKeyField object descriptors as keys", () => {
|
||||
const report = detectDuplicateRows(
|
||||
[
|
||||
{ rowNumber: 1, normalized: { email: "a@example.com" } },
|
||||
{ rowNumber: 2, normalized: { email: "a@example.com" } },
|
||||
],
|
||||
[{ field: "email", label: "Email" }],
|
||||
);
|
||||
|
||||
expect(report.groups).toEqual([
|
||||
{ id: "duplicate-group-0001", key: [{ field: "email", valuePreview: "a@example.com" }], rowNumbers: [1, 2] },
|
||||
]);
|
||||
});
|
||||
|
||||
it("falls back to positional row numbers when rows omit rowNumber", () => {
|
||||
const report = detectDuplicateRows(
|
||||
[
|
||||
{ normalized: { email: "a@example.com" } },
|
||||
{ normalized: { email: "a@example.com" } },
|
||||
{ normalized: { email: "b@example.com" } },
|
||||
],
|
||||
["email"],
|
||||
);
|
||||
|
||||
expect(report.rowResults.map((row) => row.rowNumber)).toEqual([1, 2, 3]);
|
||||
expect(report.groups).toEqual([
|
||||
{ id: "duplicate-group-0001", key: [{ field: "email", valuePreview: "a@example.com" }], rowNumbers: [1, 2] },
|
||||
]);
|
||||
});
|
||||
|
||||
it("omits the error report when configured keys yield no duplicates", () => {
|
||||
const report = detectDuplicateRows(
|
||||
[
|
||||
{ rowNumber: 1, normalized: { email: "a@example.com" } },
|
||||
{ rowNumber: 2, normalized: { email: "b@example.com" } },
|
||||
],
|
||||
["email"],
|
||||
);
|
||||
|
||||
expect(report.groups).toEqual([]);
|
||||
expect(report.summary).toMatchObject({ duplicateGroups: 0, duplicateRows: 0, diagnostics: [] });
|
||||
expect(report.errorReport).toBeUndefined();
|
||||
expect(report.rowResults.every((row) => row.ok)).toBe(true);
|
||||
});
|
||||
|
||||
it("omits the validation error report when there are no diagnostics", () => {
|
||||
const rowResults: ImportRowResult[] = [
|
||||
{ ok: true, rowNumber: 1, normalized: { email: "a@example.com" } },
|
||||
{ ok: true, rowNumber: 2, normalized: { email: "b@example.com" }, warnings: undefined },
|
||||
];
|
||||
const duplicateReport = detectDuplicateRows(
|
||||
[
|
||||
{ rowNumber: 1, normalized: { email: "a@example.com" } },
|
||||
{ rowNumber: 2, normalized: { email: "b@example.com" } },
|
||||
],
|
||||
["email"],
|
||||
);
|
||||
|
||||
const report = createValidationReport("json", rowResults, duplicateReport);
|
||||
|
||||
expect(report.summary).toMatchObject({
|
||||
format: "json",
|
||||
totalRows: 2,
|
||||
acceptedRows: 2,
|
||||
rejectedRows: 0,
|
||||
duplicateGroups: 0,
|
||||
duplicateRows: 0,
|
||||
});
|
||||
expect(report.diagnostics).toEqual([]);
|
||||
expect(report.duplicateGroups).toEqual([]);
|
||||
expect(report.errorReport).toBeUndefined();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,94 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import {
|
||||
createImportDryRunPreview,
|
||||
detectImportFormatFromContentType,
|
||||
redactDiagnosticMessage,
|
||||
} from "./index.js";
|
||||
|
||||
describe("import preview edge cases", () => {
|
||||
it("treats empty and all-blank arrays as missing required values", () => {
|
||||
const output = createImportDryRunPreview({
|
||||
format: "csv",
|
||||
fields: [{ targetField: "tags", required: true, label: "Tags" }],
|
||||
mappings: [{ sourceColumn: "Tags", targetField: "tags" }],
|
||||
rows: [
|
||||
{ rowNumber: 1, values: { Tags: [] } },
|
||||
{ rowNumber: 2, values: { Tags: [" ", null] } },
|
||||
{ rowNumber: 3, values: { Tags: ["member"] } },
|
||||
],
|
||||
});
|
||||
|
||||
expect(output.summary).toMatchObject({ totalRows: 3, acceptedRows: 1, rejectedRows: 2 });
|
||||
expect(output.rows[0]).toMatchObject({
|
||||
ok: false,
|
||||
rowNumber: 1,
|
||||
errors: [{ code: "missing_required_field", column: "tags", message: "Tags is required for import preview." }],
|
||||
});
|
||||
expect(output.rows[1]).toMatchObject({ ok: false, rowNumber: 2 });
|
||||
expect(output.rows[2]).toMatchObject({ ok: true, rowNumber: 3, normalized: { tags: ["member"] } });
|
||||
expect(output.errorReport).toMatchObject({ rejectedRows: 2 });
|
||||
});
|
||||
|
||||
it("treats numeric zero and boolean false as present required values", () => {
|
||||
const output = createImportDryRunPreview({
|
||||
format: "json",
|
||||
fields: [
|
||||
{ targetField: "score", required: true, label: "Score" },
|
||||
{ targetField: "active", required: true, label: "Active" },
|
||||
],
|
||||
mappings: [
|
||||
{ sourceColumn: "Score", targetField: "score" },
|
||||
{ sourceColumn: "Active", targetField: "active" },
|
||||
],
|
||||
rows: [{ rowNumber: 1, values: { Score: 0, Active: false } }],
|
||||
});
|
||||
|
||||
expect(output.summary).toMatchObject({ totalRows: 1, acceptedRows: 1, rejectedRows: 0 });
|
||||
expect(output.rows[0]).toMatchObject({ ok: true, rowNumber: 1, normalized: { score: 0, active: false } });
|
||||
expect(output.errorReport).toBeUndefined();
|
||||
});
|
||||
|
||||
it("normalizes present-but-null source values to null without rejecting optional fields", () => {
|
||||
const output = createImportDryRunPreview({
|
||||
format: "csv",
|
||||
fields: [{ targetField: "email", required: true, label: "Email" }],
|
||||
mappings: [
|
||||
{ sourceColumn: "Email", targetField: "email", required: true, label: "Email" },
|
||||
{ sourceColumn: "Note", targetField: "note" },
|
||||
],
|
||||
rows: [{ rowNumber: 1, values: { Email: "a@example.com", Note: null } }],
|
||||
});
|
||||
|
||||
expect(output.rows[0]).toMatchObject({ ok: true, rowNumber: 1, normalized: { email: "a@example.com", note: null } });
|
||||
expect(output.mappedRows[0]).toMatchObject({ rowNumber: 1, sourceColumns: ["Email", "Note"] });
|
||||
});
|
||||
|
||||
it("falls back to the target field name when a required field has no label", () => {
|
||||
const output = createImportDryRunPreview({
|
||||
format: "csv",
|
||||
fields: [{ targetField: "memberId", required: true }],
|
||||
mappings: [{ sourceColumn: "ID", targetField: "memberId" }],
|
||||
rows: [{ rowNumber: 4, values: { ID: "" } }],
|
||||
});
|
||||
|
||||
expect(output.rows[0]).toMatchObject({
|
||||
ok: false,
|
||||
rowNumber: 4,
|
||||
errors: [{ code: "missing_required_field", column: "memberId", message: "memberId is required for import preview." }],
|
||||
});
|
||||
});
|
||||
|
||||
it("returns undefined for content types that reduce to an empty subtype", () => {
|
||||
expect(detectImportFormatFromContentType(";")).toBeUndefined();
|
||||
expect(detectImportFormatFromContentType("; charset=utf-8")).toBeUndefined();
|
||||
});
|
||||
|
||||
it("redacts secret matches that contain both colon and equals separators", () => {
|
||||
const redacted = redactDiagnosticMessage("authorization=Bearer:token-value");
|
||||
|
||||
expect(redacted).toContain("authorization= [REDACTED]");
|
||||
expect(redacted).not.toContain("Bearer");
|
||||
expect(redacted).not.toContain("token-value");
|
||||
});
|
||||
});
|
||||
@@ -220,7 +220,7 @@ describe("imports parser contracts", () => {
|
||||
const sourcePath = path.join(path.dirname(fileURLToPath(import.meta.url)), "./index.ts");
|
||||
const source = readFileSync(sourcePath, "utf8");
|
||||
|
||||
expect(source).not.toMatch(/from\s+["'](?:@toolctrl\/db|@toolctrl\/storage|react|react-router|@prisma\/client|\.prisma|prisma)["']/);
|
||||
expect(source).not.toMatch(/import\s+["'](?:@toolctrl\/db|@toolctrl\/storage|react|react-router|@prisma\/client|\.prisma|prisma)["']/);
|
||||
expect(source).not.toMatch(/from\s+["'](?:@hivegrid\/db|@hivegrid\/storage|react|react-router|@prisma\/client|\.prisma|prisma)["']/);
|
||||
expect(source).not.toMatch(/import\s+["'](?:@hivegrid\/db|@hivegrid\/storage|react|react-router|@prisma\/client|\.prisma|prisma)["']/);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user