Phase 0 - basic shell data shapes, simple test suite, workspace configuration

This commit is contained in:
2026-07-07 04:47:13 +02:00
parent bae24e53ca
commit 3d96ad3c6d
11 changed files with 2998 additions and 0 deletions
+18
View File
@@ -0,0 +1,18 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Test Source Code",
"cwd": "${workspaceFolder}",
"runtimeExecutable": "npm",
"runtimeArgs": ["run", "test"],
"console": "integratedTerminal",
"skipFiles": ["<node_internals>/**"]
}
]
}
+28
View File
@@ -0,0 +1,28 @@
import js from "@eslint/js";
import prettier from "eslint-config-prettier";
import functional from "eslint-plugin-functional";
import tseslint from "typescript-eslint";
export default [
js.configs.recommended,
...tseslint.configs.recommended,
{
files: ["src/core/**/*.ts"],
...functional.configs.recommended,
rules: {
"functional/no-mixed-types": "off",
"@typescript-eslint/no-restricted-imports": [
"error",
{
patterns: [
{
group: ["../shell/**", "@shell/**"],
message: "Core modules cannot import from shell.",
},
],
},
],
},
},
prettier,
];
+2761
View File
File diff suppressed because it is too large Load Diff
+29
View File
@@ -0,0 +1,29 @@
{
"name": "termos",
"version": "1.0.0",
"description": "terminal emulation library that bases its functionality on the bash shell",
"main": "termos.ts",
"scripts": {
"test": "eslint . && vitest"
},
"repository": {
"type": "git",
"url": "ssh://git@git.gornodox.dev:2222/ChaosMaker/termos.git"
},
"keywords": [],
"author": "gornodox",
"license": "ISC",
"type": "module",
"devDependencies": {
"@eslint/js": "^10.0.1",
"@types/node": "^26.1.0",
"eslint": "^10.6.0",
"eslint-config-prettier": "^10.1.8",
"eslint-plugin-functional": "^10.0.0",
"eslint-plugin-prettier": "^5.5.6",
"typescript": "^6.0.3",
"typescript-eslint": "^8.63.0",
"vite-tsconfig-paths": "^6.1.1",
"vitest": "^4.1.10"
}
}
+30
View File
@@ -0,0 +1,30 @@
import type { ImmutableBuffer } from "./util/immutable_buffer";
export interface ShellError {
readonly errorType: string;
readonly message: string;
readonly timestamp: number;
readonly cause?: {
readonly name: string;
readonly message: string;
};
}
export interface ResultError<E extends ShellError> {
readonly type: "error";
readonly exitCode: number;
readonly stdout: ImmutableBuffer;
readonly stderr: ImmutableBuffer;
readonly commandName?: string;
readonly error: E;
}
export interface ResultSuccess {
readonly type: "success";
readonly exitCode: number;
readonly stdout: ImmutableBuffer;
readonly stderr: ImmutableBuffer;
readonly commandName?: string;
}
export type Result<E extends ShellError> = ResultSuccess | ResultError<E>;
+33
View File
@@ -0,0 +1,33 @@
export interface ImmutableBuffer {
readonly length: number;
get(index: number): number;
slice(start?: number, end?: number): ImmutableBuffer;
toArray(): Uint8Array;
}
export function createImmutableBuffer(input: Uint8Array): ImmutableBuffer {
const buffer = Uint8Array.from(input);
const get = (index: number): number => {
const out = buffer.at(index);
if (out === undefined) throw new Error(`Index ${index} out of bounds!`);
return out;
};
const slice = (start: number = 0, end: number = buffer.length): ImmutableBuffer => {
return createImmutableBuffer(buffer.slice(start, end));
};
const toArray = (): Uint8Array => {
return Uint8Array.from(buffer);
};
const result: ImmutableBuffer = {
length: buffer.length,
get,
slice,
toArray,
};
return Object.freeze(result);
}
+3
View File
@@ -0,0 +1,3 @@
export function sum(a: number, b: number): number {
return a + b;
}
View File
+49
View File
@@ -0,0 +1,49 @@
import type { Result, ResultError, ResultSuccess, ShellError } from "@core/result";
import { createImmutableBuffer, type ImmutableBuffer } from "@core/util/immutable_buffer";
import { expect, test } from "vitest";
interface TestError extends ShellError {
errorType: "TestError";
}
function getStdout(result: Result<TestError>) {
if (result.type === "error") throw new Error(`${result.error.message}`);
const decoder = new TextDecoder();
const decodedStdout = decoder.decode(result.stdout.toArray());
return decodedStdout;
}
test("success result passed through getstdout should return 'Hello, World!'", () => {
const message: string = "Hello, World!";
const encoder = new TextEncoder();
const stdout: ImmutableBuffer = createImmutableBuffer(encoder.encode(message));
const result: ResultSuccess = {
type: "success",
exitCode: 0,
stdout,
stderr: createImmutableBuffer(new Uint8Array()),
};
const output = getStdout(result);
expect(output).toBe(message);
});
test("error result passed through getstdout should throw error with 'Goodbye, World...'", () => {
const message: string = "Goodbye, World...";
const result: ResultError<TestError> = {
type: "error",
exitCode: 1,
stdout: createImmutableBuffer(new Uint8Array()),
stderr: createImmutableBuffer(new Uint8Array()),
error: {
errorType: "TestError",
message,
timestamp: 0,
},
};
expect(() => getStdout(result)).toThrow(message);
});
+35
View File
@@ -0,0 +1,35 @@
{
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"lib": ["ESNext", "WebWorker"],
"moduleResolution": "bundler",
"outDir": "dist",
"rootDir": "src",
"strict": true,
"esModuleInterop": true,
"noEmit": true,
"isolatedModules": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"declaration": true,
"noUncheckedIndexedAccess": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noPropertyAccessFromIndexSignature": true,
"noImplicitAny": true,
"noImplicitReturns": true,
"exactOptionalPropertyTypes": true,
"sourceMap": true,
"ignoreDeprecations": "6.0",
"baseUrl": ".",
"paths": {
"@tests/*": ["test/*"],
"@shell/*": ["src/shell/*"],
"@core/*": ["src/core/*"],
"@termos/*": ["src/*"]
}
},
"include": ["src/**/*.ts", "test/**/*.ts"],
"exclude": ["node_modules", "dist"]
}
+12
View File
@@ -0,0 +1,12 @@
import tsconfigPaths from "vite-tsconfig-paths";
import { defineConfig } from "vitest/config";
export default defineConfig({
plugins: [tsconfigPaths()],
resolve: { tsconfigPaths: true },
test: {
environment: "node",
include: ["test/**/*.test.ts"],
globals: true,
},
});