tests — interpreter

Module: tests-interpreter Cohesion: 0.80 Members: 0

tests — interpreter

This document provides an overview of the tests/interpreter/computer-skills-security.test.ts module, which is dedicated to ensuring the security and integrity of the ComputerSkills interpreter.

tests/interpreter/computer-skills-security.test.ts

1. Purpose

This module contains a suite of security regression tests for the ComputerSkills interpreter. Its primary objective is to verify that all forms of dynamic code execution and templating within skills operate within a secure, sandboxed environment. This prevents unauthorized access to system resources, execution of arbitrary code, and other potential vulnerabilities that could arise from processing untrusted or malicious skill definitions.

2. Context: The ComputerSkills Interpreter

The ComputerSkills class (located in src/interpreter/computer/skills.ts) is a core component responsible for defining, registering, and executing various "skills." These skills can encapsulate complex logic, often involving steps that require dynamic evaluation:

Given the potential for executing user-defined or dynamically generated content, robust security measures are paramount to prevent privilege escalation, data exfiltration, or system compromise.

3. Key Security Principles Validated

The tests in this module enforce the following critical security principles:

4. Test Structure and Setup

The tests are organized within a describe('ComputerSkills Security', ...) block.

    skills = new ComputerSkills({ enableBuiltin: false, cacheEnabled: false });

This setup ensures a clean, isolated environment for every test, preventing side effects from previous tests and focusing solely on the security aspects of the registered skills. enableBuiltin: false ensures no default skills are loaded, and cacheEnabled: false prevents any caching mechanisms from interfering with the test's direct interaction with the interpreter.

5. Detailed Test Cases

The module includes several specific test cases, each targeting a particular security concern:

5.1. Core Module Source Code Safety Checks

These tests directly inspect the source code of src/interpreter/computer/skills.ts to ensure that certain unsafe constructs are not present in the core implementation. This acts as a preventative measure against accidental introduction of vulnerabilities.

5.2. Sandboxed Execution for code Steps

These tests validate the runtime sandboxing of JavaScript code executed within skill code steps.

5.3. Safe Handling of condition Steps

5.4. Safe Handling of Template Interpolation

6. Relationship to the Codebase

This test module serves as a critical quality gate for the ComputerSkills class (src/interpreter/computer/skills.ts). It directly interacts with ComputerSkills by registering and running skills, then asserting the expected secure behavior. Any changes or additions to the ComputerSkills implementation, its underlying JavaScript execution engine, or its templating mechanisms must pass these tests to ensure that no security regressions are introduced. It provides confidence that the interpreter remains robust against common code injection and privilege escalation attempts.