typescript-virtual-container 1.0.8 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/README.md +138 -87
  2. package/package.json +1 -1
  3. package/src/SSHMimic/client.ts +15 -18
  4. package/src/SSHMimic/exec.ts +5 -16
  5. package/src/SSHMimic/executor.ts +18 -29
  6. package/src/SSHMimic/index.ts +23 -85
  7. package/src/VirtualFileSystem/index.ts +0 -1
  8. package/src/VirtualShell/commands/adduser.ts +2 -2
  9. package/src/VirtualShell/commands/cat.ts +3 -3
  10. package/src/VirtualShell/commands/cd.ts +2 -2
  11. package/src/VirtualShell/commands/curl.ts +2 -2
  12. package/src/VirtualShell/commands/deluser.ts +2 -2
  13. package/src/VirtualShell/commands/grep.ts +2 -2
  14. package/src/VirtualShell/commands/index.ts +13 -107
  15. package/src/VirtualShell/commands/ls.ts +6 -4
  16. package/src/VirtualShell/commands/mkdir.ts +2 -2
  17. package/src/VirtualShell/commands/nano.ts +3 -3
  18. package/src/VirtualShell/commands/neofetch.ts +2 -2
  19. package/src/VirtualShell/commands/rm.ts +2 -2
  20. package/src/VirtualShell/commands/sh.ts +2 -13
  21. package/src/VirtualShell/commands/su.ts +2 -1
  22. package/src/VirtualShell/commands/sudo.ts +3 -6
  23. package/src/VirtualShell/commands/touch.ts +3 -3
  24. package/src/VirtualShell/commands/tree.ts +2 -2
  25. package/src/VirtualShell/commands/wget.ts +2 -2
  26. package/src/VirtualShell/commands/who.ts +2 -2
  27. package/src/VirtualShell/index.ts +114 -25
  28. package/src/VirtualShell/shell.ts +25 -35
  29. package/src/{SSHMimic/users.ts → VirtualUserManager/index.ts} +6 -3
  30. package/src/index.ts +4 -4
  31. package/src/standalone.ts +19 -14
  32. package/src/types/commands.ts +3 -11
  33. package/tests/parser-executor.test.ts +3 -6
  34. package/tests/users.test.ts +1 -1
@@ -1,12 +1,8 @@
1
1
  /** Command invocation mode used by shell runtime. */
2
2
  export type CommandMode = "shell" | "exec";
3
3
 
4
- import type {
5
- VirtualActiveSession,
6
- VirtualUserManager,
7
- } from "../SSHMimic/users";
8
- import type VirtualFileSystem from "../VirtualFileSystem";
9
- import type { ShellProperties } from "../VirtualShell";
4
+ import type { VirtualShell } from "../VirtualShell";
5
+ import type { VirtualActiveSession } from "../VirtualUserManager";
10
6
 
11
7
  /**
12
8
  * Normalized command execution output.
@@ -67,8 +63,6 @@ export interface CommandContext {
67
63
  authUser: string;
68
64
  /** Virtual hostname shown in prompt and banners. */
69
65
  hostname: string;
70
- /** User and session manager instance. */
71
- users: VirtualUserManager;
72
66
  /** Snapshot of currently active user sessions. */
73
67
  activeSessions: VirtualActiveSession[];
74
68
  /** Original unparsed command line input. */
@@ -78,13 +72,11 @@ export interface CommandContext {
78
72
  /** Tokenized arguments excluding command name. */
79
73
  args: string[];
80
74
  /** Virtual shell instance. */
81
- shellProps: ShellProperties;
75
+ shell: VirtualShell;
82
76
  /** Optional stdin payload (used by pipes/redirections). */
83
77
  stdin?: string;
84
78
  /** Current working directory for command execution. */
85
79
  cwd: string;
86
- /** Virtual filesystem instance for IO operations. */
87
- vfs: VirtualFileSystem;
88
80
  }
89
81
 
90
82
  /** Contract implemented by each shell command module. */
@@ -1,7 +1,6 @@
1
1
  import { describe, expect, test } from "bun:test";
2
+ import { VirtualShell } from "../src";
2
3
  import { executePipeline } from "../src/SSHMimic/executor";
3
- import { VirtualUserManager } from "../src/SSHMimic/users";
4
- import VirtualFileSystem from "../src/VirtualFileSystem";
5
4
  import { parseShellPipeline } from "../src/VirtualShell/shellParser";
6
5
 
7
6
  describe("Pipeline parser and executor", () => {
@@ -20,18 +19,16 @@ describe("Pipeline parser and executor", () => {
20
19
  });
21
20
 
22
21
  test("executes simple pipeline", async () => {
23
- const vfs = new VirtualFileSystem("/tmp");
24
- const users = new VirtualUserManager(vfs, "root-pass");
22
+ const shell = new VirtualShell("localhost");
25
23
  const pipeline = parseShellPipeline("echo hello | grep h");
26
24
 
27
25
  const result = await executePipeline(
28
26
  pipeline,
29
27
  "root",
30
28
  "localhost",
31
- users,
32
29
  "shell",
33
30
  "/",
34
- vfs,
31
+ shell
35
32
  );
36
33
 
37
34
  expect(result.exitCode).toBe(0);
@@ -2,8 +2,8 @@ import { describe, expect, test } from "bun:test";
2
2
  import { mkdtemp, rm } from "node:fs/promises";
3
3
  import { tmpdir } from "node:os";
4
4
  import { join } from "node:path";
5
- import { VirtualUserManager } from "../src/SSHMimic/users";
6
5
  import VirtualFileSystem from "../src/VirtualFileSystem";
6
+ import { VirtualUserManager } from "../src/VirtualUserManager";
7
7
 
8
8
  async function withTempVfs(
9
9
  run: (vfs: VirtualFileSystem) => Promise<void>,