- Cleaned up old tests

- Changed `node:buffer` and `node:streams` imports to native `WebWorkers` imports;
- Fixed tests that used old `toPtr` and `fromPtr` functions to use the new NodePointer class methods
- Exposed pointer resolution helper functions to the consumer
This commit is contained in:
2026-11-20 12:22:23 +01:00
parent 2cf84ccd2f
commit d825299e26
20 changed files with 152 additions and 738 deletions
-1
View File
@@ -6,7 +6,6 @@ import { getCurrentSession } from "@core/session_manager";
import type { ShellState } from "@core/shell_state";
import type { ShellError } from "@core/util/errors";
import { resolvePath } from "@core/util/path_resolver";
import { Blob } from "node:buffer";
export const COMMAND_NAME = "touch";
+2 -4
View File
@@ -1,8 +1,6 @@
import type { UserInfo } from "@core/session_manager";
import { upTraverseTree } from "@core/util/tree_traversal";
import { VDiskManager } from "@core/util/vdisk_manager";
import type { Blob } from "node:buffer";
import type { Readable } from "node:stream";
import type {
AlreadyExistsError,
DeviceNotFoundError,
@@ -379,7 +377,7 @@ export class FileSystem {
mode: number;
owner: number;
group: number;
content: Blob | Readable;
content: Blob | ReadableStream;
size: number;
}
| { type: NodeType.Directory; mode: number; owner: number; group: number }
@@ -507,7 +505,7 @@ export class FileSystem {
await dev.writeContent((node as FileNode).content, content);
}
public streamContent(target: NodePointer): Readable {
public streamContent(target: NodePointer): ReadableStream {
const dev = this._VDiskManager.getDisk(target.device);
const node = this.resolveNode(target);
+7 -7
View File
@@ -1,6 +1,3 @@
import type { Blob } from "node:buffer";
import { Readable } from "node:stream";
import { blob } from "node:stream/consumers";
import { NodePointer, NodeType, type DirectoryNode, type Node, type NodeEntry, type NodeHash } from "./node";
export function DefaultVDiskConfig(id: number): VDiskConfig {
@@ -53,7 +50,7 @@ export interface DataConfig {
export interface IDataStore {
read(uuid: string): Promise<Uint8Array>;
stream(uuid: string): Readable;
stream(uuid: string): ReadableStream;
put(uuid: string, blob: Blob): Promise<void>;
delete(uuid: string): Promise<void>;
has(uuid: string): Promise<boolean>;
@@ -210,7 +207,7 @@ export class VDisk {
mode: number;
owner: number;
group: number;
content: Blob | Readable;
content: Blob | ReadableStream;
size: number;
}
| { type: NodeType.Directory; mode: number; owner: number; group: number }
@@ -241,7 +238,10 @@ export class VDisk {
switch (data.type) {
case NodeType.File:
node = { ...base, type: NodeType.File, content: uuid, size: data.size };
this.writeContent(uuid, data.content instanceof Readable ? await blob(data.content) : data.content);
this.writeContent(
uuid,
data.content instanceof ReadableStream ? await new Response(data.content).blob() : data.content,
);
break;
case NodeType.Directory:
node = { ...base, type: NodeType.Directory, children: new Map() };
@@ -391,7 +391,7 @@ export class VDisk {
return this._dataStore.read(uuid);
}
public streamContent(uuid: string): Readable {
public streamContent(uuid: string): ReadableStream {
return this._dataStore.stream(uuid);
}
+2 -4
View File
@@ -1,7 +1,5 @@
import type { Node } from "@core/filesystem/node";
import type { IDataStore, IMetaStore } from "@core/filesystem/vdisk";
import type { Blob } from "node:buffer";
import { Readable } from "node:stream";
export class MemMetaStore implements IMetaStore {
private _data: Map<number, Node | null> = new Map();
@@ -35,11 +33,11 @@ export class MemDataStore implements IDataStore {
return new Uint8Array(buff);
}
public stream(uuid: string): Readable {
public stream(uuid: string): ReadableStream {
const blob = this._data.get(uuid);
if (!blob) throw new Error("Content missing - " + uuid);
return Readable.from(blob.stream());
return blob.stream();
}
public put(uuid: string, blob: Blob): Promise<void> {
-6
View File
@@ -34,12 +34,6 @@ shell.on("result", payload => {
process.stdout.write("\n" + resolvePointerToHome(payload.state, getCurrentSession(payload.state).cwd) + "\n> ");
});
/*
Cant do it like this because commands also use the stdout event right before returning a result so e.g. echo will print twice
Need to use this only if a continuous process is running
*/
shell.on("stdout", payload => {
const decoded = new TextDecoder().decode(payload.data);
process.stdout.write(decoded);
+6
View File
@@ -1,2 +1,8 @@
export {
resolvePointer,
resolvePointerRelative,
resolvePointerToCwd,
resolvePointerToHome,
} from "@core/util/path_resolver";
export { Termos } from "./entry";
export { type Shell } from "./shell/index";
+1 -3
View File
@@ -1,7 +1,5 @@
import type { IDataStore, IMetaStore, VDiskConfig } from "@core/filesystem/vdisk";
import { MemDataStore, MemMetaStore } from "@core/util/temp_mem_stores";
import { Blob } from "node:buffer";
import { randomUUID } from "node:crypto";
import { NodeType, type DirectoryNode, type FileNode, type Node, type SymlinkNode } from "../core/filesystem/node";
/* export function serializeFileSystem(map: ReadonlyMap<number, TreeNode | null>): string {
@@ -66,7 +64,7 @@ export function deserializeFileSystem(json: string): { dstore: IDataStore; mstor
break;
}
case "regular": {
const uuid = randomUUID();
const uuid = crypto.randomUUID();
const fileNode: FileNode = {
type: NodeType.File,
inode: tree.inode,
+7 -1
View File
@@ -1,6 +1,6 @@
import { COMMAND_REGISTRY } from "@core/command_registry";
import { createErrorResult, type Result } from "@core/result";
import { getCurrentSession } from "@core/session_manager";
import { getCurrentSession, type SessionState } from "@core/session_manager";
import { withExitCode, withHistory, type ShellState } from "@core/shell_state";
import { SIGNAL_MAP } from "@core/signal";
import type { ShellError } from "@core/util/errors";
@@ -11,6 +11,7 @@ import { ProcessManager } from "./process_manager";
export class Shell {
private _State: Readonly<ShellState>;
private _Session: SessionState;
private _ProcessManager: ProcessManager = new ProcessManager();
private _EventEmitter: EventEmitter<ShellEventMap> = new EventEmitter();
private _GlobalKeyMap: ReadonlyMap<string, SIGNAL_MAP>;
@@ -19,6 +20,7 @@ export class Shell {
constructor(state: ShellState) {
this._State = Object.freeze(state);
this._Session = state.sessionStack[state.sessionStack.length - 1]!;
//Temporary solution for sigint keybind
const map = new Map();
@@ -103,6 +105,10 @@ export class Shell {
return this._State;
}
public get Session(): Readonly<SessionState> {
return this._Session;
}
public on<K extends keyof ShellEventMap>(type: K, handler: (payload: ShellEventMap[K]) => void): () => void {
return this._EventEmitter.on(type, handler);
}