- Fixed resolvePath

- Added symlink resolution
- Added mount resolution
- Fixed filesystem not awaiting for disks to be mounted
(now `FileSystem.init()` needs to be called with `await`)
- Removed old test fixture files
- Added a feature-full `resolvePath`test suite

*all tests passing green*
This commit is contained in:
2026-11-10 08:04:57 +01:00
parent dd804f6f14
commit 4fa284de13
14 changed files with 4608 additions and 657 deletions
+84 -15
View File
@@ -1,17 +1,23 @@
// @core/filesystem/errors.test-util.ts (adjust path to match yours)
import type {
AlreadyExistsError,
DeviceNotFoundError,
DirectoryLoopError,
FileSystemCorruptionError,
FileSystemInitializationError,
IllegalMutationError,
InvalidNodeNameError,
NodeNotFoundError,
NotADirectoryError,
NotAFileError,
} from "@core/filesystem/errors";
import type { TreeNodeType } from "@core/filesystem/node";
import type { NodeType } from "@core/filesystem/node";
import { expect } from "vitest";
export function expectThrows(fn: () => unknown, expectedShape: Record<string, unknown>) {
export async function expectThrows(fn: () => unknown, expectedShape: Record<string, unknown>) {
let thrown: unknown;
try {
fn();
await fn();
} catch (e) {
thrown = e;
}
@@ -20,19 +26,19 @@ export function expectThrows(fn: () => unknown, expectedShape: Record<string, un
expect(thrown).toMatchObject(expectedShape);
}
export function expectNotADirectoryError(fn: () => unknown, overrides?: Partial<NotADirectoryError>) {
expectThrows(fn, {
export async function expectNotADirectoryError(fn: () => unknown, overrides?: Partial<NotADirectoryError>) {
return await expectThrows(fn, {
type: "NotADirectory",
inode: expect.any(Number) as number,
message: expect.any(String) as string,
timestamp: expect.any(Number) as number,
nodeType: expect.any(Number) as TreeNodeType,
nodeType: expect.any(Number) as NodeType,
...overrides,
});
}
export function expectAlreadyExistsError(fn: () => unknown, overrides?: Partial<AlreadyExistsError>) {
expectThrows(fn, {
export async function expectAlreadyExistsError(fn: () => unknown, overrides?: Partial<AlreadyExistsError>) {
return await expectThrows(fn, {
type: "AlreadyExists",
parentInode: expect.any(Number) as number,
name: expect.any(String) as string,
@@ -42,18 +48,23 @@ export function expectAlreadyExistsError(fn: () => unknown, overrides?: Partial<
});
}
export function expectNodeNotFoundError(fn: () => unknown, overrides?: Partial<NodeNotFoundError>) {
expectThrows(fn, {
/**
* FIXED: `NodeNotFoundError` has `pointer: NodePointer` (a string), not `inode: number`.
* The previous version asserted `inode: expect.any(Number)` and would have failed
* against every real thrown `NodeNotFoundError`.
*/
export async function expectNodeNotFoundError(fn: () => unknown, overrides?: Partial<NodeNotFoundError>) {
return await expectThrows(fn, {
type: "NodeNotFound",
inode: expect.any(Number) as number,
pointer: expect.any(String) as string,
message: expect.any(String) as string,
timestamp: expect.any(Number) as number,
...overrides,
});
}
export function expectIllegalMutationError(fn: () => unknown, overrides?: Partial<IllegalMutationError>) {
expectThrows(fn, {
export async function expectIllegalMutationError(fn: () => unknown, overrides?: Partial<IllegalMutationError>) {
return await expectThrows(fn, {
type: "IllegalMutation",
message: expect.any(String) as string,
timestamp: expect.any(Number) as number,
@@ -61,8 +72,8 @@ export function expectIllegalMutationError(fn: () => unknown, overrides?: Partia
});
}
export function expectDirectoryLoopError(fn: () => void, overrides?: Partial<DirectoryLoopError>) {
expectThrows(fn, {
export async function expectDirectoryLoopError(fn: () => void, overrides?: Partial<DirectoryLoopError>) {
return await expectThrows(fn, {
type: "DirectoryLoop",
descendantInode: expect.any(Number) as number,
ancestorInode: expect.any(Number) as number,
@@ -71,3 +82,61 @@ export function expectDirectoryLoopError(fn: () => void, overrides?: Partial<Dir
...overrides,
});
}
// ---- NEW helpers below ----
export async function expectDeviceNotFoundError(fn: () => unknown, overrides?: Partial<DeviceNotFoundError>) {
return await expectThrows(fn, {
type: "DeviceNotFound",
device_id: expect.any(Number) as number,
message: expect.any(String) as string,
timestamp: expect.any(Number) as number,
...overrides,
});
}
export async function expectNotAFileError(fn: () => unknown, overrides?: Partial<NotAFileError>) {
return await expectThrows(fn, {
type: "NotAFile",
inode: expect.any(Number) as number,
message: expect.any(String) as string,
timestamp: expect.any(Number) as number,
nodeType: expect.any(Number) as NodeType,
...overrides,
});
}
export async function expectFileSystemInitializationError(
fn: () => unknown,
overrides?: Partial<FileSystemInitializationError>,
) {
return await expectThrows(fn, {
type: "FileSystemInitializationError",
message: expect.any(String) as string,
timestamp: expect.any(Number) as number,
...overrides,
});
}
export async function expectInvalidNodeNameError(fn: () => unknown, overrides?: Partial<InvalidNodeNameError>) {
return await expectThrows(fn, {
type: "InvalidNodeName",
pointer: expect.any(String) as string,
attemptedName: expect.any(String) as string,
message: expect.any(String) as string,
timestamp: expect.any(Number) as number,
...overrides,
});
}
export async function expectFileSystemCorruptionError(
fn: () => unknown,
overrides?: Partial<FileSystemCorruptionError>,
) {
return await expectThrows(fn, {
type: "FileSystemCorruption",
message: expect.any(String) as string,
timestamp: expect.any(Number) as number,
...overrides,
});
}
-91
View File
@@ -1,91 +0,0 @@
import { FileSystem } from "@core/filesystem/filesystem";
import type { TreeNode } from "@core/filesystem/node";
import type { GroupInfo, UserInfo } from "@core/session_manager";
import { createInitialShellState, type ShellState } from "@core/shell_state";
import { deserializeFileSystem } from "@shell/serializer";
import { buildTestFS } from "./filesystems_fixture";
import { depth7Tree } from "./tree_fixture";
export class Fixture {
/*
root (0)
├── folder1 (1)
│ └── subdir1 (2)
├── folder2 (3)
│ ├── subdir2 (4)
│ └── subdir3 (5)
│ └── empty-foo (6)
└── some-file (7)
*/
static rawJson = `{"atime": 1786341244,"children": [{"atime": 1786341264,"children": [{"atime": 1786341330,"children": [],"content": null,"ctime": 1786341330,"group": 1000,"inode": 2,"mode": 493,"mtime": 1786341330,"name": "subdir1","owner": 1000,"parent": 1,"type": "directory"}],"content": null,"ctime": 1786341330,"group": 1000,"inode": 1,"mode": 493,"mtime": 1786341330,"name": "folder1","owner": 1000,"parent": 0,"type": "directory"},{"atime": 1786341269,"children": [{"atime": 1786341344,"children": [],"content": null,"ctime": 1786341344,"group": 1000,"inode": 4,"mode": 493,"mtime": 1786341344,"name": "subdir2","owner": 1000,"parent": 3,"type": "directory"},{"atime": 1786341345,"children": [{"atime": 1786341356,"children": [],"content": [],"ctime": 1786341356,"group": 1000,"inode": 6,"mode": 420,"mtime": 1786341356,"name": "empty-foo","owner": 1000,"parent": 5,"type": "regular"}],"content": null,"ctime": 1786341356,"group": 1000,"inode": 5,"mode": 493,"mtime": 1786341356,"name": "subdir3","owner": 1000,"parent": 3,"type": "directory"}],"content": null,"ctime": 1786341345,"group": 1000,"inode": 3,"mode": 493,"mtime": 1786341345,"name": "folder2","owner": 1000,"parent": 0,"type": "directory"},{"atime": 1786341312,"children": [],"content": [72,101,108,108,111,44,32,87,111,114,108,100,33,10],"ctime": 1786341312,"group": 1000,"inode": 7,"mode": 420,"mtime": 1786341312,"name": "some-file","owner": 1000,"parent": 0,"type": "regular"}],"content": null,"ctime": 1786341312,"group": 1000,"inode": 0,"mode": 493,"mtime": 1786341312,"name": "root","owner": 1000,"parent": 0,"type": "directory"}`;
static user: UserInfo = {
username: "root",
uid: 0,
gid: 0, // <- PRIMARY GID
group: [0], // <- GROUPS ARRAY
home: 0,
};
static user2: UserInfo = {
username: "user",
uid: 1000,
gid: 1000,
group: [1000],
home: 1,
};
static nopass: UserInfo = {
username: "no pass",
uid: 1001,
gid: 1000,
group: [1000],
home: 2,
};
static group: GroupInfo = {
groupname: "root",
gid: 0,
members: [0], // <- UID
};
static group2: GroupInfo = {
groupname: "user",
gid: 1000,
members: [1000, 1001], // <- UID
};
public static get State(): ShellState {
const rawJson = `{"atime": 1786341244,"children": [{"atime": 1786341264,"children": [{"atime": 1786341330,"children": [],"content": null,"ctime": 1786341330,"group": 1000,"inode": 2,"mode": 493,"mtime": 1786341330,"name": "subdir1","owner": 1000,"parent": 1,"type": "directory"}],"content": null,"ctime": 1786341330,"group": 1000,"inode": 1,"mode": 493,"mtime": 1786341330,"name": "folder1","owner": 1000,"parent": 0,"type": "directory"},{"atime": 1786341269,"children": [{"atime": 1786341344,"children": [],"content": null,"ctime": 1786341344,"group": 1000,"inode": 4,"mode": 493,"mtime": 1786341344,"name": "subdir2","owner": 1000,"parent": 3,"type": "directory"},{"atime": 1786341345,"children": [{"atime": 1786341356,"children": [],"content": [],"ctime": 1786341356,"group": 1000,"inode": 6,"mode": 420,"mtime": 1786341356,"name": "empty-foo","owner": 1000,"parent": 5,"type": "regular"}],"content": null,"ctime": 1786341356,"group": 1000,"inode": 5,"mode": 493,"mtime": 1786341356,"name": "subdir3","owner": 1000,"parent": 3,"type": "directory"}],"content": null,"ctime": 1786341345,"group": 1000,"inode": 3,"mode": 493,"mtime": 1786341345,"name": "folder2","owner": 1000,"parent": 0,"type": "directory"},{"atime": 1786341312,"children": [],"content": [72,101,108,108,111,44,32,87,111,114,108,100,33,10],"ctime": 1786341312,"group": 1000,"inode": 7,"mode": 420,"mtime": 1786341312,"name": "some-file","owner": 1000,"parent": 0,"type": "regular"}],"content": null,"ctime": 1786341312,"group": 1000,"inode": 0,"mode": 493,"mtime": 1786341312,"name": "root","owner": 1000,"parent": 0,"type": "directory"}`;
const base = deserializeFileSystem(rawJson);
const overlay: ReadonlyMap<number, TreeNode | null> = new Map();
const fs = FileSystem.init(base, overlay, base.size - 1);
const users: Map<number, UserInfo> = new Map();
const groups: Map<number, GroupInfo> = new Map();
users.set(0, Fixture.user);
users.set(1000, Fixture.user2);
users.set(1001, Fixture.nopass);
groups.set(0, Fixture.group);
groups.set(1000, Fixture.group2);
return createInitialShellState(fs, users, groups, Fixture.user);
}
}
export class Fixture7Depth extends Fixture {
public static get State(): ShellState {
const fs = buildTestFS(depth7Tree);
const users: Map<number, UserInfo> = new Map();
const groups: Map<number, GroupInfo> = new Map();
users.set(0, Fixture7Depth.user);
users.set(1000, Fixture7Depth.user2);
groups.set(0, Fixture7Depth.group);
groups.set(1000, Fixture7Depth.group2);
return createInitialShellState(fs, users, groups, Fixture7Depth.user);
}
}
-58
View File
@@ -1,58 +0,0 @@
import type { FixtureNode } from "./filesystems_fixture";
export const depth7Tree: FixtureNode = {
inode: 0,
name: "root",
type: "Dir",
children: [
{
inode: 1,
name: "d1",
type: "Dir",
children: [
{
inode: 2,
name: "d2",
type: "Dir",
children: [
{
inode: 3,
name: "d3",
type: "Dir",
children: [
{
inode: 4,
name: "d4",
type: "Dir",
children: [
{
inode: 5,
name: "d5",
type: "Dir",
children: [
{
inode: 6,
name: "d6",
type: "Dir",
children: [
{
inode: 7,
name: "deep_file.txt",
type: "File",
content: "Deepest node at depth 7",
children: [],
},
],
},
],
},
],
},
],
},
],
},
],
},
],
};