Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/Java/Openclaw/test/scripts/   (KI Agentensystem Version 22©)  Datei vom 26.3.2026 mit Größe 2 kB image not shown  

Quelle  check-dynamic-import-warts.test.ts

  Sprache: JAVA
 

Spracherkennung für: .ts vermutete Sprache: Unknown {[0] [0] [0]} [Methode: Schwerpunktbildung, einfache Gewichte, sechs Dimensionen]

import { describe, expect, it } from "vitest";
import { findDynamicImportAdvisories } from "../../scripts/check-dynamic-import-warts.mjs";

describe("check-dynamic-import-warts", () => {
  it("flags runtime static plus dynamic imports of the same module", () => {
    const source = `
      import { run } from "./runtime.js";
      export async function start() {
        return await import("./runtime.js");
      }
    `;
    expect(findDynamicImportAdvisories(source)).toEqual([
      {
        line: 4,
        reason: 'runtime static + dynamic import of "./runtime.js" (static line 2)',
      },
    ]);
  });

  it("ignores type-only static imports", () => {
    const source = `
      import { type Runtime } from "./runtime.js";
      export async function start(): Promise<Runtime> {
        return (await import("./runtime.js")).createRuntime();
      }
    `;
    expect(findDynamicImportAdvisories(source)).toEqual([]);
  });

  it("flags repeated direct dynamic imports", () => {
    const source = `
      export async function one() {
        return await import("./runtime.js");
      }
      export async function two() {
        return await import("./runtime.js");
      }
    `;
    expect(findDynamicImportAdvisories(source)).toEqual([
      {
        line: 3,
        reason: 'repeated direct dynamic import of "./runtime.js" (2 callsites: 3, 6)',
      },
    ]);
  });

  it("ignores cached loader patterns", () => {
    const source = `
      let runtimePromise: Promise<typeof import("./runtime.js")> | undefined;
      function loadRuntime() {
        runtimePromise ??= import("./runtime.js");
        return runtimePromise;
      }
    `;
    expect(findDynamicImportAdvisories(source)).toEqual([]);
  });

  it("flags direct dynamic imports inside execute paths", () => {
    const source = `
      export function createTool() {
        return {
          execute: async () => {
            return await import("./runtime.js");
          },
        };
      }
    `;
    expect(findDynamicImportAdvisories(source)).toEqual([
      {
        line: 5,
        reason:
          'direct dynamic import of "./runtime.js" inside execute path; move it behind a cached loader',
      },
    ]);
  });

  it("allows execute paths that call cached loaders", () => {
    const source = `
      let runtimePromise: Promise<typeof import("./runtime.js")> | undefined;
      function loadRuntime() {
        runtimePromise ??= import("./runtime.js");
        return runtimePromise;
      }
      export function createTool() {
        return {
          execute: async () => await loadRuntime(),
        };
      }
    `;
    expect(findDynamicImportAdvisories(source)).toEqual([]);
  });
});

¤ Dauer der Verarbeitung: 0.14 Sekunden  (vorverarbeitet am  2026-04-27) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.