Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,23 +1,39 @@
import { describe, expect, it, vi } from 'vitest';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { beforeEach, describe, expect, it, vi } from 'vitest';

import { render, screen } from '@/tests/utils/render';

import type { Document } from '../hooks/queries';

let mockDocument: Partial<Document> | undefined;

// The dialog point-queries the document and resolves a storage URL; stub both
// so the component mounts without a live Convex backend. Returning no URL lands
// the body on the lightweight "failed to load" branch — enough to render the
// header, which is what this test inspects.
vi.mock('../hooks/queries', () => ({
useDocument: () => ({ data: undefined, isLoading: false }),
useDocument: () => ({ data: mockDocument, isLoading: false }),
}));
vi.mock('@/app/features/shared/files/use-file-url', () => ({
useFileUrl: () => ({ data: undefined, isLoading: false }),
}));
vi.mock('@tale/ui/use-toast', () => ({
useToast: () => ({ toast: vi.fn() }),
}));
// A document with a URL renders its file and the details sidebar; the file
// body has its own tests, and with no organization in scope the sidebar's
// team and legal-hold reads stay idle.
vi.mock('./document-preview', () => ({ DocumentPreview: () => null }));
vi.mock('@/app/hooks/use-organization-id', () => ({
useOrganizationId: () => undefined,
}));

import { DocumentPreviewDialog } from './document-preview-dialog';

beforeEach(() => {
mockDocument = undefined;
});

describe('DocumentPreviewDialog', () => {
it('exposes the "Document preview" heading exactly once', () => {
render(
Expand All @@ -36,4 +52,45 @@ describe('DocumentPreviewDialog', () => {
screen.getAllByRole('heading', { name: 'Document preview' }),
).toHaveLength(1);
});

// #3603: the badge read the backend's epoch-millisecond stamp as seconds,
// and the sidebar's Indexed dialog dated the indexing in the year 58711.
describe('indexing status', () => {
// 10:00Z is 28 September from UTC−10 to UTC+13, whatever zone runs this.
const indexedAt = Date.parse('2026-09-28T10:00:00.000Z');

it.each([
{ ragIndexedAt: indexedAt, shows: 'September 28, 2026' },
{ ragIndexedAt: undefined, shows: 'Unknown' },
])(
'shows $shows in the Indexed dialog',
async ({ ragIndexedAt, shows }) => {
mockDocument = {
id: 'doc-1',
name: 'report.pdf',
url: 'https://files.example/report.pdf',
ragStatus: 'completed',
ragIndexedAt,
};
const { user } = render(
// The RAG status badge holds its retry action, a react-query
// mutation; the sidebar's reads are react-query too.
<QueryClientProvider client={new QueryClient()}>
<DocumentPreviewDialog
open
onOpenChange={vi.fn()}
documentId="doc-1"
/>
</QueryClientProvider>,
);

await user.click(
screen.getByRole('button', { name: 'Document indexed' }),
);
const dialog = screen.getByRole('dialog', { name: 'Document indexed' });
expect(dialog).toHaveTextContent(`Indexed on: ${shows}`);
expect(dialog).not.toHaveTextContent('58711');
},
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,18 @@ vi.mock('../hooks/actions', () => ({

import { RagStatusBadge } from './rag-status-badge';

// What the backend sends for an indexing that completed at 10:00Z on
// 28 September 2026: both producers stamp `Date.now()` into
// `rag_indexed_at_ms`, and the views pass it through unchanged.
const INDEXED_AT_MS = Date.parse('2026-09-28T10:00:00.000Z');

describe('RagStatusBadge', () => {
describe('accessibility', () => {
it('passes axe audit with completed status', async () => {
const { container } = render(
<RagStatusBadge
status="completed"
indexedAt={1700000000}
indexedAt={INDEXED_AT_MS}
documentId="doc-1"
/>,
);
Expand Down Expand Up @@ -125,6 +130,49 @@ describe('RagStatusBadge', () => {
});
});

// #3603: the badge read the stamp as seconds and multiplied it by 1000
// again, so the Indexed dialog dated the indexing in the year 58711.
describe('indexed date', () => {
const openIndexedDialog = () => {
fireEvent.click(
screen.getByRole('button', {
name: 'documents.rag.dialog.indexed.title',
}),
);
return screen.getByRole('dialog');
};

it('dates the dialog from the epoch milliseconds the backend sends', () => {
render(
<RagStatusBadge
status="completed"
indexedAt={INDEXED_AT_MS}
documentId="doc-1"
/>,
);
expect(openIndexedDialog()).toHaveTextContent('2026-09-28T10:00:00.000Z');
});

// A missing stamp reads as unknown, and so does one the shared epoch-ms
// bound refuses: no `Date` holds 9e15, so it would print "Invalid Date".
it.each([
['no stamp', undefined],
['a negative stamp', -1],
['a stamp past the latest Date', 9e15],
])('reads %s as an unknown date', (_case, indexedAt) => {
render(
<RagStatusBadge
status="completed"
indexedAt={indexedAt}
documentId="doc-1"
/>,
);
expect(openIndexedDialog()).toHaveTextContent(
'documents.rag.status.unknown',
);
});
});

// Issue #2598: a format with no text extractor is a terminal state, not a
// transient one — unlike `failed`, it must never offer a retry affordance
// (retrying can never succeed).
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use client';

import { isEpochMs } from '@tale/shared/schemas/epoch-ms';
import { Badge, type BadgeProps } from '@tale/ui/badge';
import { Button } from '@tale/ui/button';
import { ViewDialog } from '@tale/ui/dialog/view-dialog';
Expand All @@ -20,7 +21,7 @@ import { EmbeddingNotConfiguredGuidance } from './embedding-settings-action';

interface RagStatusBadgeProps {
status: RagStatus | undefined;
/** Timestamp (in seconds) when the document was indexed */
/** When indexing completed, in epoch milliseconds (`rag_indexed_at_ms`) */
indexedAt?: number;
/** Error message (for failed status) */
error?: string;
Expand Down Expand Up @@ -137,7 +138,9 @@ export function RagStatusBadge({

// Show clickable dialog with indexed date for completed status
if (effectiveStatus === 'completed') {
const indexedDate = indexedAt ? new Date(indexedAt * 1000) : null;
// Epoch milliseconds, as every producer stamps it; a stamp outside the
// shared bound reads as unknown, like a missing one.
const indexedDate = isEpochMs(indexedAt) ? new Date(indexedAt) : null;
const formattedDate = indexedDate
? formatDate(indexedDate, 'long')
: t('rag.status.unknown');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @vitest-environment jsdom
import '@testing-library/jest-dom/vitest';
import { AppShell } from '@tale/ui/app-shell';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { render, renderHook, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import type { ReactNode } from 'react';
Expand All @@ -18,11 +19,16 @@ vi.mock('@/app/hooks/use-current-user', () => ({
useCurrentUser: () => ({ data: { userId: 'user_owner' } }),
}));

// The RAG status badge holds its retry action, a react-query mutation.
const queryClient = new QueryClient();

function Providers({ children }: { children: ReactNode }) {
return (
<AppShell i18n={i18n} locale={{ mode: 'client' }}>
{children}
</AppShell>
<QueryClientProvider client={queryClient}>
<AppShell i18n={i18n} locale={{ mode: 'client' }}>
{children}
</AppShell>
</QueryClientProvider>
);
}

Expand Down Expand Up @@ -367,3 +373,26 @@ describe('useDocumentsTableConfig — source cell', () => {
);
});
});

// #3603: the badge read the backend's epoch-millisecond stamp as seconds,
// and the Indexed dialog dated the indexing in the year 58711.
describe('useDocumentsTableConfig — ragStatus cell', () => {
// 10:00Z is 28 September from UTC−10 to UTC+13, whatever zone runs this.
const indexedAt = Date.parse('2026-09-28T10:00:00.000Z');

it.each([
{ ragIndexedAt: indexedAt, shows: 'September 28, 2026' },
{ ragIndexedAt: undefined, shows: 'Unknown' },
])('shows $shows in the Indexed dialog', async ({ ragIndexedAt, shows }) => {
const { user } = renderColumnCellWithUser('ragStatus', {
type: 'file',
id: 'doc-1',
ragStatus: 'completed',
ragIndexedAt,
});
await user.click(screen.getByRole('button', { name: 'Document indexed' }));
const dialog = screen.getByRole('dialog', { name: 'Document indexed' });
expect(dialog).toHaveTextContent(`Indexed on: ${shows}`);
expect(dialog).not.toHaveTextContent('58711');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { describe, expect, it, vi } from 'vitest';

import { render, screen } from '@/tests/utils/render';

import type { KnowledgeEntryItem } from '../hooks/queries';
import { KnowledgeEntryViewDialog } from './knowledge-entry-view-dialog';

// Unlike its sibling suite, this one keeps the real RAG status badge: the
// stamp a knowledge-entry listing carries has to reach its Indexed dialog.
vi.mock('../hooks/queries', () => ({
useKnowledgeEntryVersions: () => ({ data: null }),
}));

// #3603: the badge read the backend's epoch-millisecond stamp as seconds,
// and the Indexed dialog dated the indexing in the year 58711.
describe('KnowledgeEntryViewDialog — indexing status', () => {
// 10:00Z is 28 September from UTC−10 to UTC+13, whatever zone runs this.
const indexedAt = Date.parse('2026-09-28T10:00:00.000Z');

it.each([
{ ragIndexedAt: indexedAt, shows: 'September 28, 2026' },
{ ragIndexedAt: undefined, shows: 'Unknown' },
])('shows $shows in the Indexed dialog', async ({ ragIndexedAt, shows }) => {
const entry: KnowledgeEntryItem = {
_id: 'entry-2' as never,
_creationTime: Date.parse('2026-09-21T08:00:00.000Z'),
organizationId: 'org-1',
topic: 'Shipping times',
topicKey: 'shipping times',
content: 'Orders over CHF 100 ship free.',
status: 'active',
source: 'manual',
createdBy: 'user-1',
createdAt: Date.parse('2026-09-21T08:00:00.000Z'),
documentId: 'doc-1',
ragStatus: 'completed',
ragIndexedAt,
};
const { user } = render(
// The RAG status badge holds its retry action, a react-query mutation.
<QueryClientProvider client={new QueryClient()}>
<KnowledgeEntryViewDialog isOpen onClose={vi.fn()} entry={entry} />
</QueryClientProvider>,
);

await user.click(screen.getByRole('button', { name: 'Document indexed' }));
const dialog = screen.getByRole('dialog', { name: 'Document indexed' });
expect(dialog).toHaveTextContent(`Indexed on: ${shows}`);
expect(dialog).not.toHaveTextContent('58711');
});
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// @vitest-environment jsdom
import '@testing-library/jest-dom/vitest';
import { AppShell } from '@tale/ui/app-shell';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { render, renderHook, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import type { ReactNode } from 'react';
import { describe, expect, it } from 'vitest';

Expand All @@ -10,11 +12,16 @@ import { i18n } from '@/lib/i18n/i18n';
import type { KnowledgeEntryItem } from './queries';
import { useKnowledgeEntriesTableConfig } from './use-knowledge-entries-table-config';

// The RAG status badge holds its retry action, a react-query mutation.
const queryClient = new QueryClient();

function Providers({ children }: { children: ReactNode }) {
return (
<AppShell i18n={i18n} locale={{ mode: 'client' }}>
{children}
</AppShell>
<QueryClientProvider client={queryClient}>
<AppShell i18n={i18n} locale={{ mode: 'client' }}>
{children}
</AppShell>
</QueryClientProvider>
);
}

Expand Down Expand Up @@ -91,3 +98,26 @@ describe('useKnowledgeEntriesTableConfig — content cell', () => {
);
});
});

// #3603: the badge read the backend's epoch-millisecond stamp as seconds,
// and the Indexed dialog dated the indexing in the year 58711.
describe('useKnowledgeEntriesTableConfig — ragStatus cell', () => {
// 10:00Z is 28 September from UTC−10 to UTC+13, whatever zone runs this.
const indexedAt = Date.parse('2026-09-28T10:00:00.000Z');

it.each([
{ ragIndexedAt: indexedAt, shows: 'September 28, 2026' },
{ ragIndexedAt: undefined, shows: 'Unknown' },
])('shows $shows in the Indexed dialog', async ({ ragIndexedAt, shows }) => {
const user = userEvent.setup();
renderColumnCell('ragStatus', {
documentId: 'doc-1',
ragStatus: 'completed',
ragIndexedAt,
});
await user.click(screen.getByRole('button', { name: 'Document indexed' }));
const dialog = screen.getByRole('dialog', { name: 'Document indexed' });
expect(dialog).toHaveTextContent(`Indexed on: ${shows}`);
expect(dialog).not.toHaveTextContent('58711');
});
});
1 change: 1 addition & 0 deletions services/platform/tests/manual/reference/automation.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ Legend: ✅ fully automated · 🔶 partially automated · ⛔ manual-only (no s
| [skills](../suites/skills.md) | Doors after the 2026-09-14 round-h evaluation: the skill file read is validated (`ETag`, `Last-Modified`, 304 on `If-None-Match` / `If-Modified-Since`); a missing session is the coded `UNAUTHORIZED` envelope on `/events` and the app routes; `Expect` is stripped at the proxy; the rendered reference keeps a pasted key out of `localStorage`; the MCP `start_run` takes `idempotencyKey` through the REST ledger, `set_trigger` answers a webhook token once with `deployed`, `get_automation` reads `version: "deployed"`, `list_versions` marks the deployed row, every capability refusal carries a `code`, the registry holds deployed automations only, an enum argument outside its set is named with the set | ✅ automated | `backend/rest/v1-core.contract.test.ts`, `backend/auth/session.test.ts`, `app/routes/docs.test.tsx`, `lib/engine/api/dispatch.refusals.test.ts`, `backend/core/automations_builder/mcp_http.test.ts`, `lib/chat/capabilities.test.ts`, `backend/domains/chat/capabilities.test.ts` |
| [knowledge](../suites/knowledge.md) | `KNOW-F16` half: a cloud-sync config that fails opens a failure episode on its row (`error_since_ms` / `failure_notified_at_ms`), stamps `needs-reauth` for a dead grant, tells the owner once per episode (at once for a dead grant, after an hour otherwise, again only when the cause escalates), hints the folder rows so the badge shows without a reload, and the run that reaches the source again clears the episode and marks the bell read; the hub folder listing decorates active AND errored configs with `sync` (provider, status, needsReauth, owner) and a directly picked synced file carries the same | ✅ automated | `backend/domains/onedrive/sync-health.test.ts`, `backend/domains/onedrive/service.failure-notify.test.ts`, `app/features/documents/hooks/use-documents-table-config.test.tsx` (the Source cell), `backend/integration-check.ts` (`onedrive dead grant: one needs-reauth episode → bell + flagged folder, cleared by recovery`) |
| [knowledge](../suites/knowledge.md) | `KNOW-F19` half: one provenance map (`useDocumentSource`) names every source for the Source cell and the preview sidebar — OneDrive, SharePoint and Google Drive synced or not, upload, agent, knowledge entry, API, WebDAV, Confluence, a REST caller's own word, nothing without a provenance; the cell shows no text and its words are the accessible name and tooltip, passing axe; a failed sync is a button named by its dialog title, with a warning or unplugged glyph whose tooltip opens on keyboard focus | ✅ automated (fit, preview sidebar and dark theme 🔶 — stay in `KNOW-F19`) | `app/features/documents/hooks/use-document-source.test.tsx`, `app/features/documents/hooks/use-documents-table-config.test.tsx` (the Source cell) |
| [knowledge](../suites/knowledge.md) | The **Indexed** dialog (`documents.rag.dialog.indexed.title`) dates a completed indexing from the epoch-millisecond stamp the backend sends (`rag_indexed_at_ms`, #3603) in the Documents table and preview and the Knowledge entries table and details; a missing stamp, or one outside the shared epoch-ms bound, reads **Unknown** (`documents.rag.status.unknown`) | ✅ component | `app/features/documents/components/rag-status-badge.test.tsx`, `app/features/documents/hooks/use-documents-table-config.test.tsx`, `app/features/documents/components/document-preview-dialog.test.tsx`, `app/features/knowledge-entries/hooks/use-knowledge-entries-table-config.test.tsx`, `app/features/knowledge-entries/components/knowledge-entry-view-dialog.indexed-date.test.tsx` |
| [notifications](../suites/notifications.md) | `NOTIF-F16` half: the `cloud_sync_failed` row's keys exist in every locale and substitute fully (static titles), both deep-link builders (bell + email) open the listing that holds the synced item, the type is actionable and its server-side inbox mirror matches the catalogs | ✅ automated | `lib/i18n/notification-keys.test.ts`, `app/features/notifications/lib/notification-target.test.ts`, `app/features/notifications/lib/notification-target.parity.test.ts`, `backend/core/notifications/notification_messages.test.ts` |
| [knowledge](../suites/knowledge.md) | `KNOW-F2` half: the Documents page lists ONE folder at a time — the root page (`GET /documents/paginated` with no `folderId`) answers only the documents that sit in no folder, a folder id answers that folder, and there is no shape that lists the whole hub; a synced OneDrive/Google Drive folder's files stand inside their folder, never beside it at the root (the first Postgres port listed every document under the root — one row rendered twice, gone from both places when the folder was deleted, 2026-09-14); a cloud import refreshes the folder list as well as the documents, so its sync-root folder shows without a reload | ✅ automated | `backend/domains/documents/service.paginated.test.ts`, `backend/integration-check.ts` (`hub root page lists unfiled documents only (synced folder files stand in their folder, not beside it)` and `paginated hub walk (keyset, disjoint, exhausts, one folder at a time)` — a document moved into `Contracts/2026` leaves the root walk and is paged from its folder) |
| [projects](../suites/projects.md) | REST `folderId=root` (contract 1.10.0): `GET /api/v1/documents?folderId=root` answers the hub documents in no folder and `GET /api/v1/projects/{id}/files?folderId=root` the project's files in no folder — the root no folder id could name — while a folder id answers that one folder (a foreign id stays the opaque 404 `FOLDER_NOT_FOUND`) and an omitted `folderId` still lists everything | ✅ automated | `backend/rest/v1-core.test.ts` (`GET /documents folder filter`), `backend/rest/v1-projects.test.ts` (`GET /projects/:id/files folder filter`), `scripts/openapi/spec.test.ts` (the fingerprint moved with 1.10.0) |
Expand Down
2 changes: 1 addition & 1 deletion services/platform/types/documents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export interface DocumentItem {
* row). Absent for anything that is not synced. */
syncHealth?: DocumentSyncHealth;
ragStatus?: RagStatus;
/** Timestamp when the document was indexed (for completed status) */
/** When indexing completed, in epoch milliseconds (for completed status) */
ragIndexedAt?: number;
/** Error message (for failed status) */
ragError?: string;
Expand Down