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
2 changes: 2 additions & 0 deletions .github/workflows/native-api-sdk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ jobs:
npm run test:editor:block-start-hints 2>&1 | tee "$RUNNER_TEMP/document-markdown-hints.log"
npm run test:editor:markdown 2>&1 | tee "$RUNNER_TEMP/document-markdown-roundtrip.log"
npm run test:collaboration:location-client 2>&1 | tee "$RUNNER_TEMP/document-location-client.log"
npm run test:workspaces:path-alias-observations 2>&1 | tee "$RUNNER_TEMP/document-path-alias-observations.log"
- name: Opened document resource policy
run: |
set -euo pipefail
Expand Down Expand Up @@ -178,6 +179,7 @@ jobs:
if-no-files-found: error
path: |
${{ runner.temp }}/source-projection-lock.log
${{ runner.temp }}/document-path-alias-observations.log
${{ runner.temp }}/document-retention-policy.log
${{ runner.temp }}/document-live-tabs.log
${{ runner.temp }}/document-tab-open.log
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ This project uses calendar-style release versions, currently `YYYY.M.D.N`.

- Nothing yet.

### Fixed

- Refresh contradictory filesystem observations once during read-only path checks. A brief canonical file or directory replacement no longer reports a false path-alias conflict; symlink, case-alias and mutation checks retain their protections.

## [2026.11.8.2] - 2026-11-08

### Added
Expand Down
23 changes: 16 additions & 7 deletions app/lib/workspaces/path-guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,23 @@ export async function assertWorkspacePathHasNoAliases(
: await ensureWorkspaceRoot(workspace);
for (const segment of segments) {
const candidate = path.join(parent, segment);
let stat: Awaited<ReturnType<typeof fs.lstat>>;
try { stat = await fs.lstat(candidate); }
catch (error) {
if (error && typeof error === 'object' && 'code' in error && error.code === 'ENOENT') return;
throw error;
const observations = options.readOnly ? 2 : 1;
for (let attempt = 0; attempt < observations; attempt++) {
let stat: Awaited<ReturnType<typeof fs.lstat>>;
try { stat = await fs.lstat(candidate); }
catch (error) {
if (error && typeof error === 'object' && 'code' in error && error.code === 'ENOENT') return;
throw error;
}
if (stat.isSymbolicLink()) throw new WorkspacePathAliasError();
if ((await fs.readdir(parent)).includes(segment)) {
parent = candidate;
break;
}
// A read may observe a changed entry between lstat and readdir. Refresh
// both observations once; mutation checks retain their fenced rejection.
if (attempt + 1 === observations) throw new WorkspacePathAliasError();
}
if (stat.isSymbolicLink() || !(await fs.readdir(parent)).includes(segment)) throw new WorkspacePathAliasError();
parent = candidate;
}
}

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,7 @@
"test:auth:setup": "tsx --conditions react-server scripts/auth-setup-test.ts",
"test:workspaces:bootstrap": "tsx --conditions react-server scripts/workspace-bootstrap-idempotency-test.ts",
"test:workspaces:bootstrap:native": "NODE_ENV=test CANVAS_SHARED_CONNECTION_POSTGRES_TEST=1 tsx --conditions react-server scripts/workspace-bootstrap-idempotency-test.ts --native",
"test:workspaces:path-alias-observations": "NODE_ENV=test tsx --conditions react-server --test scripts/workspace-path-alias-observation-test.ts",
"test:auth:seat-limit": "tsx --conditions react-server scripts/auth-seat-limit-test.ts",
"test:mobile:compatibility": "tsx --conditions react-server scripts/mobile-compatibility-test.ts && tsx --conditions react-server scripts/mobile-compatibility-route-test.ts && tsx --conditions react-server scripts/mobile-app-promotion-test.ts && tsx --conditions react-server scripts/mobile-app-promotion-postgres-test.ts && tsx scripts/mobile-setup-link-test.ts && tsx scripts/mobile-setup-card-ui-test.tsx",
"test:mobile:bootstrap": "tsx --conditions react-server scripts/mobile-bootstrap-test.ts && tsx --conditions react-server scripts/mobile-bootstrap-route-test.ts",
Expand Down Expand Up @@ -1110,7 +1111,7 @@
"test:api-keys:proxy": "NODE_ENV=test tsx --conditions react-server scripts/api-key-workspace-proxy-test.ts",
"test:api-keys:errors": "NODE_ENV=test tsx --conditions react-server scripts/api-key-error-result-test.ts",
"test:all:runner": "node --test scripts/test-all-orchestration-test.mjs",
"test:collaboration:regular:contracts": "tsx --test scripts/regular-collaboration-profile-test.mjs scripts/owned-fixture-files-test.mjs scripts/recovered-room-read-test.mjs scripts/completed-native-rename-test.ts",
"test:collaboration:regular:contracts": "tsx --test scripts/regular-collaboration-profile-test.mjs scripts/owned-fixture-files-test.mjs scripts/recovered-room-read-test.mjs scripts/completed-native-rename-test.ts && npm run test:workspaces:path-alias-observations",
"test:e2e:collaboration:regular": "E2E_EXTERNAL_SERVER=1 COLLABORATION_E2E=1 CANVAS_REGULAR_COLLABORATION_E2E=1 playwright test --config tests/playwright/playwright.regular-collaboration.config.ts --workers=1 --max-failures=0"
},
"dependencies": {
Expand Down
192 changes: 192 additions & 0 deletions scripts/workspace-path-alias-observation-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
import assert from 'node:assert/strict';
import { promises as fs } from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import test from 'node:test';

import { assertWorkspacePathHasNoAliases } from '../app/lib/workspaces/path-guard';
import type { WorkspaceContext } from '../app/lib/workspaces/types';

const originalReaddir = fs.readdir;
const contents = Buffer.from('[Document](nested/document.md)\n');
type Fixture = { root: string; file: string; workspace: WorkspaceContext };

async function withFixture(run: (fixture: Fixture) => Promise<void>): Promise<void> {
const root = await fs.realpath(await fs.mkdtemp(path.join(os.tmpdir(), 'canvas-path-observation-')));
await fs.chmod(root, 0o700);
const file = path.join(root, 'Verweise.md');
const workspace: WorkspaceContext = {
workspaceId: 'owned-path-observation', workspaceType: 'personal', rootPath: root,
organizationId: null, ownerUserId: 'owned-path-observation', legacy: false,
permissions: { canRead: true, canWrite: true, canDelete: true, canCreatePublicLinks: true,
canManageWorkspace: true, canRunAgent: true },
};
try {
await fs.writeFile(file, contents);
await run({ root, file, workspace });
} finally {
Object.defineProperty(fs, 'readdir', { value: originalReaddir });
await fs.rm(root, { recursive: true, force: true });
}
}

async function duringDirectoryObservation(
root: string,
observe: (readActualDirectory: () => Promise<string[]>) => Promise<string[]>,
run: () => Promise<void>,
): Promise<void> {
// Interpose real rename/symlink operations between the guard's real lstat
// and real readdir; never invent directory entries or replace lstat results.
Object.defineProperty(fs, 'readdir', { value: async (parent: unknown, ...options: unknown[]) => {
if (String(parent) === root && options.length === 0) return observe(() => originalReaddir(root));
return Reflect.apply(originalReaddir, fs, [parent, ...options]);
} });
try { await run(); }
finally { Object.defineProperty(fs, 'readdir', { value: originalReaddir }); }
}

test('canonical paths retain their exact bytes for read and mutation checks', async () => {
await withFixture(async ({ file, workspace }) => {
await assertWorkspacePathHasNoAliases(workspace, 'Verweise.md', { readOnly: true });
await assertWorkspacePathHasNoAliases(workspace, 'Verweise.md');
assert.deepEqual(await fs.readFile(file), contents);
});
});

test('a configured root symlink remains supported', async () => {
await withFixture(async ({ root, file, workspace }) => {
const configuredRoot = path.join(root, 'configured-root');
await fs.symlink(root, configuredRoot, 'dir');
await assertWorkspacePathHasNoAliases({ ...workspace, rootPath: configuredRoot }, 'Verweise.md', { readOnly: true });
assert.deepEqual(await fs.readFile(file), contents);
});
});

test('real file and directory symlinks remain rejected for reads and mutations', async () => {
await withFixture(async ({ root, file, workspace }) => {
await fs.symlink('Verweise.md', path.join(root, 'alias.md'));
await fs.symlink(root, path.join(root, 'directory-alias'), 'dir');
for (const alias of ['alias.md', 'directory-alias/Verweise.md']) {
for (const options of [{ readOnly: true }, {}]) {
await assert.rejects(assertWorkspacePathHasNoAliases(workspace, alias, options), { code: 'WORKSPACE_PATH_ALIAS' });
}
}
assert.deepEqual(await fs.readFile(file), contents);
});
});

test('case-folding aliases stay rejected; distinct-case missing paths stay pristine', async (context) => {
await withFixture(async ({ root, workspace }) => {
const caseFolded = await fs.lstat(path.join(root, 'verweise.md')).catch(() => null);
for (const options of [{ readOnly: true }, {}]) {
if (caseFolded) {
await assert.rejects(assertWorkspacePathHasNoAliases(workspace, 'verweise.md', options), { code: 'WORKSPACE_PATH_ALIAS' });
} else {
await assertWorkspacePathHasNoAliases(workspace, 'verweise.md', options);
await assert.rejects(fs.lstat(path.join(root, 'verweise.md')), { code: 'ENOENT' });
}
}
context.diagnostic(caseFolded ? 'Actual case-folding filesystem alias checked.' : 'Actual case-sensitive missing-name contract checked.');
});
});

test('a read refreshes a directory observation after a canonical file disappears and returns', async () => {
await withFixture(async ({ root, file, workspace }) => {
let moved = false;
await duringDirectoryObservation(root, async read => {
if (moved) return read();
moved = true;
const staged = path.join(root, '.owned-transition');
await fs.rename(file, staged);
try { return await read(); }
finally { await fs.rename(staged, file); }
}, () => assertWorkspacePathHasNoAliases(workspace, 'Verweise.md', { readOnly: true }));
assert(moved);
assert((await fs.lstat(file)).isFile());
assert.deepEqual(await fs.readFile(file), contents);
});
});

test('a read refreshes a changed parent-directory observation before descending', async () => {
await withFixture(async ({ root, workspace }) => {
const directory = path.join(root, 'folder'), staged = path.join(root, '.owned-directory');
await fs.mkdir(directory);
await fs.writeFile(path.join(directory, 'note.md'), contents);
let moved = false;
await duringDirectoryObservation(root, async read => {
if (moved) return read();
moved = true;
await fs.rename(directory, staged);
try { return await read(); }
finally { await fs.rename(staged, directory); }
}, () => assertWorkspacePathHasNoAliases(workspace, 'folder/note.md', { readOnly: true }));
assert(moved);
assert.deepEqual(await fs.readFile(path.join(directory, 'note.md')), contents);
});
});

test('a newly missing suffix remains missing and never becomes an alias or recreated file', async () => {
await withFixture(async ({ root, file, workspace }) => {
const staged = path.join(root, '.owned-removed-entry');
let moved = false;
await duringDirectoryObservation(root, async read => {
if (!moved) { moved = true; await fs.rename(file, staged); }
return read();
}, () => assertWorkspacePathHasNoAliases(workspace, 'Verweise.md', { readOnly: true }));
assert(moved);
await assert.rejects(fs.lstat(file), { code: 'ENOENT' });
assert.deepEqual(await fs.readFile(staged), contents);
});
});

test('a symlink appearing after the first observation is rejected on the fresh check', async () => {
await withFixture(async ({ root, file, workspace }) => {
const staged = path.join(root, '.owned-symlink-target');
let moved = false;
await duringDirectoryObservation(root, async read => {
if (moved) return read();
moved = true;
await fs.rename(file, staged);
const entries = await read();
await fs.symlink('.owned-symlink-target', file);
return entries;
}, () => assert.rejects(assertWorkspacePathHasNoAliases(workspace, 'Verweise.md', { readOnly: true }), { code: 'WORKSPACE_PATH_ALIAS' }));
assert(moved);
assert((await fs.lstat(file)).isSymbolicLink());
assert.deepEqual(await fs.readFile(staged), contents);
});
});

test('mutation checks still reject inconsistent directory evidence without retrying a write', async () => {
await withFixture(async ({ root, file, workspace }) => {
await duringDirectoryObservation(root, async read => {
const staged = path.join(root, '.owned-write-transition');
await fs.rename(file, staged);
try { return await read(); }
finally { await fs.rename(staged, file); }
}, () => assert.rejects(assertWorkspacePathHasNoAliases(workspace, 'Verweise.md'), { code: 'WORKSPACE_PATH_ALIAS' }));
assert.deepEqual(await fs.readFile(file), contents);
});
});

test('continuously inconsistent observations remain bounded and fail closed', async () => {
await withFixture(async ({ root, file, workspace }) => {
let observations = 0;
await duringDirectoryObservation(root, async read => {
assert(++observations <= 3, 'A read must not spin on a changing directory.');
const staged = path.join(root, '.owned-continuous-transition');
await fs.rename(file, staged);
try { return await read(); }
finally { await fs.rename(staged, file); }
}, () => assert.rejects(assertWorkspacePathHasNoAliases(workspace, 'Verweise.md', { readOnly: true }), { code: 'WORKSPACE_PATH_ALIAS' }));
assert.deepEqual(await fs.readFile(file), contents);
});
});

test('read-only checks never create a missing workspace root', async () => {
await withFixture(async ({ root, workspace }) => {
const missingRoot = path.join(root, 'missing-root');
await assert.rejects(assertWorkspacePathHasNoAliases({ ...workspace, rootPath: missingRoot }, 'future.md', { readOnly: true }), { code: 'ENOENT' });
await assert.rejects(fs.lstat(missingRoot), { code: 'ENOENT' });
});
});
8 changes: 8 additions & 0 deletions tests/studio-bulk-experimental.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,14 @@ async function toggleFromSettings(page: Page, enabled: boolean): Promise<void> {
await expect(switchControl).toBeChecked({ checked: enabled });
}

async function waitForStudioWorkspace(page: Page): Promise<void> {
// Workspace resolution replaces the initial Studio header subtree.
await expect(page.getByRole('banner').locator('[data-testid="workspace-switcher"]:visible'))
.toHaveAttribute('data-active-workspace-id', /\S+/);
}

async function assertLauncherBulk(page: Page, enabled: boolean): Promise<void> {
await waitForStudioWorkspace(page);
console.info(`[studio-bulk-e2e] launcher ${enabled ? 'enabled' : 'disabled'}: open apps at ${new URL(page.url()).pathname}`);
await page.getByRole('button', { name: launcherLabel }).click();
console.info('[studio-bulk-e2e] launcher: open Studio actions');
Expand All @@ -336,6 +343,7 @@ async function assertLauncherBulk(page: Page, enabled: boolean): Promise<void> {
}

async function assertMobileNavigation(page: Page, enabled: boolean): Promise<void> {
await waitForStudioWorkspace(page);
await page.getByRole('button', { name: 'Studio', exact: true }).click();
const menu = page.getByRole('menu');
await expect(menu.getByRole('menuitem', { name: /^(?:Models|Modelle)$/ })).toBeVisible();
Expand Down
Loading