- Old tests fixed

- Added a static Fixuture class for test mockups
This commit is contained in:
2026-08-28 16:52:59 +02:00
parent 310218663d
commit 1ee2a2fe7a
13 changed files with 161 additions and 306 deletions
+5 -39
View File
@@ -1,48 +1,14 @@
import { FileSystem } from "@core/filesystem/filesystem";
import { TreeNodeType, type DirectoryNode, type TreeNode } from "@core/filesystem/treenode";
import type { UserInfo } from "@core/session_manager";
import { getCurrentSession } from "@core/session_manager";
import { createInitialShellState, withCwd, withEnv, withExitCode, withHistory } from "@core/shell_state";
import { withCwd, withEnv, withExitCode, withHistory } from "@core/shell_state";
import { Fixture } from "@tests/helpers/state_fixture";
import { expect, test } from "vitest";
const map: Map<number, TreeNode> = new Map();
const time = Date.now();
const root: DirectoryNode = {
type: TreeNodeType.Directory,
inode: 0,
name: "root",
parent: 0,
mode: 0o555,
owner: 0,
group: 0,
mtime: time,
atime: time,
ctime: time,
children: {},
};
map.set(0, root);
const base: ReadonlyMap<number, TreeNode> = map;
const overlay: ReadonlyMap<number, TreeNode | null> = new Map();
const fs = FileSystem.init(base, overlay, 0);
const users: Map<number, UserInfo> = new Map();
const user: UserInfo = {
username: "root",
uid: 0,
gid: 0,
group: [0],
home: 0,
};
users.set(0, user);
const state = createInitialShellState(fs, users, user);
const state = Fixture.State;
test("createInitialShellState - initializes successfully", () => {
expect(state.sessionStack.at(0)).toBeDefined();
expect(state.users.get(user.uid)).toEqual(user);
expect(state.users.get(Fixture.user.uid)).toEqual(Fixture.user);
expect(Object.isFrozen(state)).toBe(true);
});
@@ -61,7 +27,7 @@ test("getCurrentSession - successfully returns the current (top most) session fr
expect(session.exitCode).toBe(0);
expect(session.history).toEqual([]);
expect(session.envVars.size).toBe(0);
expect(session.user).toBe(user);
expect(session.user).toBe(Fixture.user);
});
test("withCwd", () => {