|
@@ -1,3 +1,4 @@
|
|
|
|
+// METADATA // {"ai-commented":{"service":"claude"}}
|
|
/*
|
|
/*
|
|
* Copyright (C) 2024 Puter Technologies Inc.
|
|
* Copyright (C) 2024 Puter Technologies Inc.
|
|
*
|
|
*
|
|
@@ -24,6 +25,10 @@ const { Context } = require("../src/util/context");
|
|
const { Kernel } = require("../src/Kernel");
|
|
const { Kernel } = require("../src/Kernel");
|
|
const { HTTPThumbnailService } = require("../src/services/thumbnails/HTTPThumbnailService");
|
|
const { HTTPThumbnailService } = require("../src/services/thumbnails/HTTPThumbnailService");
|
|
|
|
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * A simple implementation of the log interface for the test kernel.
|
|
|
|
+ */
|
|
class TestLogger {
|
|
class TestLogger {
|
|
constructor () {
|
|
constructor () {
|
|
console.log(
|
|
console.log(
|
|
@@ -44,6 +49,16 @@ class TestLogger {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+* TestKernel class extends AdvancedBase to provide a testing environment for Puter services
|
|
|
|
+* Implements a simplified version of the main Kernel for testing purposes, including:
|
|
|
|
+* - Module management and installation
|
|
|
|
+* - Service container initialization
|
|
|
|
+* - Custom logging functionality
|
|
|
|
+* - Context creation and management
|
|
|
|
+* Does not include full service initialization or legacy service support
|
|
|
|
+*/
|
|
class TestKernel extends AdvancedBase {
|
|
class TestKernel extends AdvancedBase {
|
|
constructor () {
|
|
constructor () {
|
|
super();
|
|
super();
|
|
@@ -51,6 +66,12 @@ class TestKernel extends AdvancedBase {
|
|
this.modules = [];
|
|
this.modules = [];
|
|
this.useapi = useapi();
|
|
this.useapi = useapi();
|
|
|
|
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Initializes the useapi instance for the test kernel.
|
|
|
|
+ * Defines base Module and Service classes in the useapi context.
|
|
|
|
+ * @returns {void}
|
|
|
|
+ */
|
|
this.useapi.withuse(() => {
|
|
this.useapi.withuse(() => {
|
|
def('Module', AdvancedBase)
|
|
def('Module', AdvancedBase)
|
|
def('Service', BaseService)
|
|
def('Service', BaseService)
|
|
@@ -63,6 +84,12 @@ class TestKernel extends AdvancedBase {
|
|
this.modules.push(module);
|
|
this.modules.push(module);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Adds a module to the test kernel's module list
|
|
|
|
+ * @param {Module} module - The module instance to add
|
|
|
|
+ * @description Stores the provided module in the kernel's internal modules array for later installation
|
|
|
|
+ */
|
|
boot () {
|
|
boot () {
|
|
const { consoleLogManager } = require('../src/util/consolelog');
|
|
const { consoleLogManager } = require('../src/util/consolelog');
|
|
consoleLogManager.initialize_proxy_methods();
|
|
consoleLogManager.initialize_proxy_methods();
|
|
@@ -85,6 +112,7 @@ class TestKernel extends AdvancedBase {
|
|
}, 'app');
|
|
}, 'app');
|
|
globalThis.root_context = root_context;
|
|
globalThis.root_context = root_context;
|
|
|
|
|
|
|
|
+
|
|
root_context.arun(async () => {
|
|
root_context.arun(async () => {
|
|
await this._install_modules();
|
|
await this._install_modules();
|
|
// await this._boot_services();
|
|
// await this._boot_services();
|
|
@@ -94,6 +122,10 @@ class TestKernel extends AdvancedBase {
|
|
Error.stackTraceLimit = 200;
|
|
Error.stackTraceLimit = 200;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Installs modules into the test kernel environment
|
|
|
|
+ */
|
|
async _install_modules () {
|
|
async _install_modules () {
|
|
const { services } = this;
|
|
const { services } = this;
|
|
|
|
|
|
@@ -144,9 +176,15 @@ k.boot();
|
|
|
|
|
|
const do_after_tests_ = [];
|
|
const do_after_tests_ = [];
|
|
|
|
|
|
-// const do_after_tests = (fn) => {
|
|
|
|
-// do_after_tests_.push(fn);
|
|
|
|
-// };
|
|
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+* Executes a function immediately and adds it to the list of functions to be executed after tests
|
|
|
|
+*
|
|
|
|
+* This is used to log things inline with console output from tests, and then
|
|
|
|
+* again later without those console outputs.
|
|
|
|
+*
|
|
|
|
+* @param {Function} fn - The function to execute and store for later
|
|
|
|
+*/
|
|
const repeat_after = (fn) => {
|
|
const repeat_after = (fn) => {
|
|
fn();
|
|
fn();
|
|
do_after_tests_.push(fn);
|
|
do_after_tests_.push(fn);
|
|
@@ -155,6 +193,12 @@ const repeat_after = (fn) => {
|
|
let total_passed = 0;
|
|
let total_passed = 0;
|
|
let total_failed = 0;
|
|
let total_failed = 0;
|
|
|
|
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+* Tracks test results across all services
|
|
|
|
+* @type {number} total_passed - Count of all passed assertions
|
|
|
|
+* @type {number} total_failed - Count of all failed assertions
|
|
|
|
+*/
|
|
const main = async () => {
|
|
const main = async () => {
|
|
console.log('awaiting services readty');
|
|
console.log('awaiting services readty');
|
|
await k.services.ready;
|
|
await k.services.ready;
|
|
@@ -178,6 +222,7 @@ const main = async () => {
|
|
let passed = 0;
|
|
let passed = 0;
|
|
let failed = 0;
|
|
let failed = 0;
|
|
|
|
|
|
|
|
+
|
|
repeat_after(() => {
|
|
repeat_after(() => {
|
|
console.log(`\x1B[33;1m=== [ Service :: ${name} ] ===\x1B[0m`);
|
|
console.log(`\x1B[33;1m=== [ Service :: ${name} ] ===\x1B[0m`);
|
|
});
|
|
});
|