DEV Community

Cover image for Measuring AI Agent Readiness in a TypeScript Codebase
Remo H. Jansen
Remo H. Jansen

Posted on

Measuring AI Agent Readiness in a TypeScript Codebase

AI is changing the economics of software development.

When code generation becomes cheaper, the ability to verify generated code becomes increasingly important. This changes how we should think about software architecture, type systems, testing and CI/CD.

A codebase that is easy for an experienced developer to understand is not necessarily easy for an AI agent to work with. Similarly, a codebase with high test coverage is not necessarily a codebase in which an agent can safely make changes.

We need to think beyond code quality.

We need to think about AI agent readiness.

But what does that actually mean? And how could we measure it?

From code quality to agent readiness

Traditional code quality assessments tend to focus on properties such as maintainability, complexity, duplication, test coverage and security.

These properties remain important, but they don't tell us the whole story.

An AI coding agent needs to do more than generate code. It needs to:

  • Understand the existing architecture.
  • Discover where new functionality belongs.
  • Understand the contracts between modules.
  • Identify business rules and invariants.
  • Make changes without breaking unrelated functionality.
  • Detect incorrect implementations.
  • Verify that its changes are correct.
  • Understand failures and determine how to resolve them.

This introduces a different set of questions.

Can an agent understand the architecture without reconstructing it from thousands of files?

Can it determine whether a dependency violates an architectural boundary?

Can it distinguish between a meaningful test and a test that simply executes code?

Can it detect when its implementation is incorrect?

Most importantly, can it independently establish that its work is complete?

These questions suggest that AI agent readiness is a property of the entire software development environment, not simply the source code.

Let's explore how we could evaluate it in a TypeScript codebase.

1. Type-system strength and explicitness

The TypeScript compiler is one of the most important verification tools available to an AI agent.

Types communicate intent. They describe contracts, constrain implementations and make certain categories of mistakes detectable before runtime.

However, simply using TypeScript doesn't mean that a codebase has a strong type system.

Consider the following configuration:

{
  "compilerOptions": {
    "strict": false,
    "noImplicitAny": false,
    "strictNullChecks": false
  }
}
Enter fullscreen mode Exit fullscreen mode

This provides relatively few guarantees.

A readiness assessment should examine:

  • Whether strict mode is enabled.
  • The frequency of explicit and implicit any.
  • The use of unknown at external boundaries.
  • Excessive type assertions and non-null assertions.
  • Whether public functions have meaningful signatures.
  • Whether discriminated unions represent domain states.
  • Whether exhaustive checks are used.
  • Whether branded types distinguish otherwise interchangeable primitives.
  • Whether readonly types are used appropriately.
  • Whether generic constraints express meaningful requirements.
  • Whether type definitions are duplicated.
  • Whether compiler suppressions are justified.
  • Whether all relevant source files are included in compilation.

Tools such as TypeScript, typescript-eslint, type-coverage and tsd can provide much of the objective evidence.

The LLM's role is to interpret that evidence and identify places where the type system communicates less intent than it should.

For example, an agent should be able to distinguish between a legitimate type assertion at a trusted boundary and an assertion that simply suppresses a type error.

The objective isn't to eliminate every type assertion. It's to understand where the codebase relies on assumptions rather than guarantees.

2. Runtime validation and explicit contracts

TypeScript types disappear at runtime.

An API response, environment variable, database result or message from a queue doesn't become trustworthy simply because it has been assigned a TypeScript interface.

Consider:

interface User {
  id: string;
  email: string;
}

const user = await response.json() as User;
Enter fullscreen mode Exit fullscreen mode

The compiler accepts this, but nothing guarantees that the response actually represents a valid User.

A readiness assessment should investigate whether untrusted data is validated at system boundaries.

This includes:

  • HTTP request inputs.
  • Third-party API responses.
  • Environment variables.
  • Database boundaries.
  • Queue messages.
  • Event payloads.
  • Configuration files.
  • Deserialised data.

It should also examine whether runtime schemas and TypeScript types remain consistent.

Libraries such as Zod, Valibot, TypeBox and Ajv can help establish explicit runtime contracts.

The important question is whether an agent can determine where data enters the system and what guarantees are established before that data is used.

3. Architecture and dependency integrity

Architecture is often documented through conventions, diagrams and developer knowledge.

Unfortunately, conventions are easy to violate, particularly when an AI agent is modifying unfamiliar parts of a codebase.

Architecture should therefore be executable wherever possible.

For example, consider a layered architecture:

Presentation
     |
Application
     |
Domain
     |
Infrastructure
Enter fullscreen mode Exit fullscreen mode

The intended dependency direction might be:

Presentation -> Application -> Domain
Infrastructure -> Application / Domain
Enter fullscreen mode Exit fullscreen mode

An agent should be able to discover these rules and verify that the actual dependency graph respects them.

A readiness assessment should check:

  • Circular dependencies.
  • Dependency direction.
  • Layer boundaries.
  • Forbidden imports.
  • Module isolation.
  • Public module interfaces.
  • Cross-feature dependencies.
  • Package boundaries.
  • Internal implementation leakage.
  • Dependency inversion.
  • Unintended coupling through barrel files.

Tools such as dependency-cruiser, Madge, ESLint boundaries, Nx module boundaries and ArchUnitTS can make these rules executable.

Consider this dependency-cruiser configuration:

{
  name: 'domain-must-not-depend-on-infrastructure',
  from: {
    path: '^src/domain'
  },
  to: {
    path: '^src/infrastructure'
  }
}
Enter fullscreen mode Exit fullscreen mode

The specific configuration will vary, but the principle is important.

An architectural decision should ideally be represented by an automated constraint rather than relying exclusively on documentation.

For an AI agent, this turns architectural intent into something it can verify.

4. Unit testing quality

Test coverage is useful, but it is a relatively weak indicator of test quality.

A test can execute every line of a function without verifying that the function behaves correctly.

An agent readiness assessment should examine:

  • Statement, branch, function and line coverage.
  • Boundary conditions.
  • Error handling.
  • Regression tests.
  • Determinism.
  • Test isolation.
  • Assertion quality.
  • Test naming and readability.
  • Excessive mocking.
  • Whether tests verify behaviour or implementation details.

It should also inspect critical business logic separately from the overall coverage percentage.

For example, 90% overall coverage might look impressive, but what happens if the most important pricing calculation has no meaningful tests?

The objective is not simply to establish whether code is executed. It is to establish whether incorrect behaviour is detected.

5. Mutation testing

Mutation testing is particularly interesting in the context of AI-generated code.

It addresses a question that ordinary coverage cannot answer:

Would the tests detect an incorrect implementation?

Mutation testing tools deliberately introduce small changes into the source code.

For example:

function isEligible(age: number): boolean {
  return age >= 18;
}
Enter fullscreen mode Exit fullscreen mode

A mutation might change the comparison:

function isEligible(age: number): boolean {
  return age > 18;
}
Enter fullscreen mode Exit fullscreen mode

If the test suite still passes, it may not adequately cover the boundary condition.

An assessment should examine:

  • Overall mutation score.
  • Surviving mutants.
  • Mutation score for critical business logic.
  • Mutation testing scope.
  • Equivalent mutants.
  • Mutation thresholds.
  • Whether mutation testing is executed in CI or scheduled pipelines.

StrykerJS is an excellent tool for mutation testing in TypeScript projects.

I would pay particular attention to mutation scores for critical business logic rather than relying exclusively on one aggregate percentage.

A codebase might have excellent overall mutation results while important business rules remain insufficiently protected.

6. Integration, contract and end-to-end testing

Unit tests cannot establish that independently correct components work correctly together.

An agent needs confidence in the contracts between modules and external systems.

The assessment should investigate:

  • Database integration tests.
  • Repository contract tests.
  • API integration tests.
  • Event producer and consumer contracts.
  • Queue message validation.
  • External service integrations.
  • Transaction behaviour.
  • Serialization and deserialization.
  • API backward compatibility.
  • Database migration compatibility.

Tools such as Testcontainers, Pact, MSW, Supertest and Playwright can provide executable evidence

Top comments (0)