---
id: video/Q-oazDEucLE
type: video
title: 20260601 - From No Tests to Safe Refactors Debug Logging + AI Agents for Legacy AL
summary: Areopa webinar (a rerun of a Days of Knowledge talk) on using AI agents to refactor legacy AL code safely. It covers compiler and linter feedback with warnings treated as errors, and debug logging by intercepting feature telemetry through a test-app telemetry logger that writes JSONL files in the container. It also covers temporary approval (characterization) tests, agent-run mutation testing, and a TDD loop using wrapper procedures. These are presented as a development workflow, not as product features.
tier: community
language: en
tags:
  - legacy code
  - test-driven development
  - ai agents
  - refactoring
  - static analysis
  - linters
  - al code quality
  - ci/cd
  - automated testing
  - debug logging
  - telemetry
  - code paths
system: development
review:
  state: reviewed
  by: opus
  at: "2026-10-07T23:20:16.843Z"
  flags: []
generated:
  at: "2026-10-07T23:20:16.915Z"
  pipeline: 0.2.0
  prompts:
    extract-video: 1
    summarize-video: 2
  input_hash: 0a86249b1a806e3ad214cb266b1ec355c170426a36112f1674ea225422b36241
evidence:
  - kind: video
    url: https://www.youtube.com/watch?v=Q-oazDEucLE&t=352s
    title: 20260601 - From No Tests to Safe Refactors Debug Logging + AI Agents for Legacy AL
    date: "2026-06-02T07:17:56.000Z"
    commit: null
    t: 352
    quote: This is projects that where already exist a lot of code and you are supposed to make another feature, fix a bug, do some
  - kind: video
    url: https://www.youtube.com/watch?v=Q-oazDEucLE&t=369s
    title: 20260601 - From No Tests to Safe Refactors Debug Logging + AI Agents for Legacy AL
    date: "2026-06-02T07:17:56.000Z"
    commit: null
    t: 369
    quote: If you are in in the same circles as I am, then there is a lot of legacy AL code.
  - kind: video
    url: https://www.youtube.com/watch?v=Q-oazDEucLE&t=437s
    title: 20260601 - From No Tests to Safe Refactors Debug Logging + AI Agents for Legacy AL
    date: "2026-06-02T07:17:56.000Z"
    commit: null
    t: 437
    quote: We have got an AI and AI is really good at writing very very fast code and not code that uh that executes fast
  - kind: video
    url: https://www.youtube.com/watch?v=Q-oazDEucLE&t=487s
    title: 20260601 - From No Tests to Safe Refactors Debug Logging + AI Agents for Legacy AL
    date: "2026-06-02T07:17:56.000Z"
    commit: null
    t: 487
    quote: Every one of the things that AI actually is really good at is understanding uh the principles behind uh testdriven development writing test and
  - kind: video
    url: https://www.youtube.com/watch?v=Q-oazDEucLE&t=608s
    title: 20260601 - From No Tests to Safe Refactors Debug Logging + AI Agents for Legacy AL
    date: "2026-06-02T07:17:56.000Z"
    commit: null
    t: 608
    quote: Every time she makes a change ask it to compile uh the app and and that can be done nowhere you have test or
links:
  learn: []
  objects: []
  features: []
  topics: []
  localizations: []
  videos: []
  posts: []
  guidelines: []
video_id: Q-oazDEucLE
channel: yt-areopa
source_name: Areopa webinars
url: https://www.youtube.com/watch?v=Q-oazDEucLE
published_at: "2026-06-02T07:17:56.000Z"
duration_s: 3262
captions: derived
audience:
  - developer
chapters:
  - t: 0
    title: Webinar introduction and housekeeping
  - t: 225
    title: Speaker introduction and background
  - t: 315
    title: Problem statement - legacy code and brownfields projects
  - t: 426
    title: AI capabilities and challenges in code generation
  - t: 583
    title: Making AI deterministic - compilation and static analysis
  - t: 702
    title: Linters, complexity rules, and test-driven development
  - t: 827
    title: Automated testing and CI/CD integration
  - t: 891
    title: Understanding legacy code behavior
  - t: 999
    title: Mapping procedure behavior and test coverage
  - t: 1167
    title: Enabling agents to see code execution paths
  - t: 1264
    title: Debug logging implementation with telemetry
  - t: 1480
    title: Automating test verification and path detection
  - t: 1630
    title: Approval tests and safe refactoring foundations
  - t: 1738
    title: Mutation testing introduction and purpose
  - t: 1878
    title: Mutation testing execution with agent automation
  - t: 1984
    title: Test-driven development loop and refactoring workflow
  - t: 2071
    title: Wrapper procedures and test compatibility during refactoring
  - t: 2145
    title: Agent economics and cascading benefits of clean code
  - t: 2235
    title: Ensuring agent compliance with instructions and hooks
  - t: 2363
    title: Test setup and agent learning for refactoring
  - t: 2472
    title: Code quality rules and refactoring practices
  - t: 2599
    title: Debug logging and feature telemetry safety nets
  - t: 2788
    title: Mutation testing with AI agents
  - t: 2906
    title: Temporary vs permanent test coverage
  - t: 3031
    title: Real unit tests and bug discovery in refactoring
  - t: 3166
    title: Closing remarks and webinar information
features:
  - name: AI code generation for legacy AL refactoring
    status: unclear
    t: 437
    verified: false
    status_source: video
  - name: Compilation as first-pass validation for AI agents
    status: unclear
    t: 608
    verified: false
    status_source: video
  - name: Static analysis linters for code quality
    status: unclear
    t: 646
    verified: false
    status_source: video
  - name: Complexity linters for procedure length control
    status: unclear
    t: 702
    verified: false
    status_source: video
  - name: Warning-as-errors compiler option with ruleset files
    status: unclear
    t: 736
    verified: false
    status_source: video
  - name: Test-driven development with AI agents
    status: unclear
    t: 788
    verified: false
    status_source: video
  - name: Build automation and CI/CD for agent loops
    status: unclear
    t: 867
    verified: false
    status_source: video
  - name: Debug logging via telemetry interception
    status: unclear
    t: 1264
    verified: false
    status_source: video
  - name: Observational test patterns for code discovery
    status: unclear
    t: 1549
    verified: false
    status_source: video
  - name: Automated path coverage verification
    status: unclear
    t: 1549
    verified: false
    status_source: video
  - name: Approval testing for refactoring preparation
    status: unclear
    t: 1656
    verified: false
    status_source: video
  - name: Mutation testing for scenario coverage verification
    status: unclear
    t: 1738
    verified: false
    status_source: video
  - name: Test-driven development loop in refactoring
    status: unclear
    t: 1984
    verified: false
    status_source: video
  - name: Wrapper procedures for safe refactoring
    status: unclear
    t: 2071
    verified: false
    status_source: video
  - name: Agent-assisted economics of safe refactoring
    status: unclear
    t: 2145
    verified: false
    status_source: video
  - name: Large language model selection for AL code
    status: unclear
    t: 2262
    verified: false
    status_source: video
  - name: Git hooks for agent instruction enforcement
    status: unclear
    t: 2320
    verified: false
    status_source: video
  - name: Tests as project documentation for agents
    status: unclear
    t: 2404
    verified: false
    status_source: video
  - name: AI Agent for test execution and verification
    status: unclear
    t: 2349
    verified: false
    status_source: video
  - name: Leave codebase better rule
    status: unclear
    t: 2449
    verified: false
    status_source: video
  - name: Touch code only when necessary
    status: unclear
    t: 2491
    verified: false
    status_source: video
  - name: AI-assisted test development playbook
    status: unclear
    t: 2512
    verified: false
    status_source: video
  - name: Debug logging with feature telemetry safety nets
    status: unclear
    t: 2664
    verified: false
    status_source: video
  - name: AI-generated mutation testing plans
    status: unclear
    t: 2788
    verified: false
    status_source: video
  - name: Characterization testing for legacy code
    status: unclear
    t: 2962
    verified: false
    status_source: video
  - name: Real unit and integration tests after refactoring
    status: unclear
    t: 3031
    verified: false
    status_source: video
  - name: Bug discovery during decoupling and refactoring
    status: unclear
    t: 3085
    verified: false
    status_source: video
objects_mentioned:
  - other MCP server
  - interface telemetry logger interface
  - codeunit test telemetry logger
  - other CI/CD check
  - other feature telemetry
  - other mutation plan
  - other AL test framework
quotes:
  - t: 352
    text: This is projects that where already exist a lot of code and you are supposed to make another feature, fix a bug, do some
    check: exact
  - t: 369
    text: If you are in in the same circles as I am, then there is a lot of legacy AL code.
    check: exact
  - t: 437
    text: We have got an AI and AI is really good at writing very very fast code and not code that uh that executes fast
    check: exact
  - t: 487
    text: Every one of the things that AI actually is really good at is understanding uh the principles behind uh testdriven development writing test and
    check: exact
  - t: 608
    text: Every time she makes a change ask it to compile uh the app and and that can be done nowhere you have test or
    check: exact
---

# 20260601 - From No Tests to Safe Refactors Debug Logging + AI Agents for Legacy AL

> Areopa webinar (a rerun of a Days of Knowledge talk) on using AI agents to refactor legacy AL code safely. It covers compiler and linter feedback with warnings treated as errors, and debug logging by intercepting feature telemetry through a test-app telemetry logger that writes JSONL files in the container. It also covers temporary approval (characterization) tests, agent-run mutation testing, and a TDD loop using wrapper procedures. These are presented as a development workflow, not as product features.

[Watch on YouTube](https://www.youtube.com/watch?v=Q-oazDEucLE) · Areopa webinars · 2026-06-02 · 54:22 · tier community · reviewed (checked by Opus)

## Overview

The webinar covers brownfield AL projects where a lot of legacy code exists and AI agents are used to refactor it. It starts by making agent output more deterministic: compile after every change, use linters including complexity rules, treat warnings as errors with a ruleset file, and run automated tests in CI/CD.

The main part is a workflow for code with no tests. Debug log markers in if statements and cases are written as JSONL files inside the container through the feature telemetry logger interface, so an agent can see which code paths a test ran, without the 2-5 minute delay of Application Insights. Approval tests capture existing behavior, bugs included. Mutation testing, run by an agent, checks that scenarios are really covered. A TDD loop and wrapper procedures then let the same tests validate old and new implementations. The speaker also covers keeping characterization tests temporary and replacing them with real unit tests.

## Key points

- Compile after every agent change and use complexity linters, so overly long procedures cause compiler errors. Pair this with the command-line option to treat warnings as errors and a ruleset file.
- Debug logging implements the telemetry logger interface in a test app with the same publisher. This intercepts feature telemetry and writes JSONL files inside the container. The files are available immediately, unlike Application Insights with its 2 to 5 minute delay. The call is asynchronous and does not block code.
- Debug log markers in if statements and cases show which code paths a test hit. They replace manual breakpoint debugging, and a CI/CD check fails on feature telemetry messages starting with debug, so markers are not shipped.
- Approval (characterization) tests record existing behavior and let bugs pass, so refactoring stays one-to-one. They are temporary because they need heavy setup and database access and run slowly.
- Mutation testing changes one production code element at a time to confirm a test fails. The agent writes a mutation plan for critical paths, the developer reviews it, and the agent runs the compile, publish, test, revert cycle using git from a clean repository. This can take an hour or two.
- Wrapper procedures with the same signature route calls to the old or new implementation, so the same approval tests validate both.
- After refactoring, write real unit and integration tests. Bugs found in the legacy code are listed and fixed only after the refactor is complete.

## Chapters

- [0:00](https://www.youtube.com/watch?v=Q-oazDEucLE&t=0s) Webinar introduction and housekeeping
- [3:45](https://www.youtube.com/watch?v=Q-oazDEucLE&t=225s) Speaker introduction and background
- [5:15](https://www.youtube.com/watch?v=Q-oazDEucLE&t=315s) Problem statement - legacy code and brownfields projects
- [7:06](https://www.youtube.com/watch?v=Q-oazDEucLE&t=426s) AI capabilities and challenges in code generation
- [9:43](https://www.youtube.com/watch?v=Q-oazDEucLE&t=583s) Making AI deterministic - compilation and static analysis
- [11:42](https://www.youtube.com/watch?v=Q-oazDEucLE&t=702s) Linters, complexity rules, and test-driven development
- [13:47](https://www.youtube.com/watch?v=Q-oazDEucLE&t=827s) Automated testing and CI/CD integration
- [14:51](https://www.youtube.com/watch?v=Q-oazDEucLE&t=891s) Understanding legacy code behavior
- [16:39](https://www.youtube.com/watch?v=Q-oazDEucLE&t=999s) Mapping procedure behavior and test coverage
- [19:27](https://www.youtube.com/watch?v=Q-oazDEucLE&t=1167s) Enabling agents to see code execution paths
- [21:04](https://www.youtube.com/watch?v=Q-oazDEucLE&t=1264s) Debug logging implementation with telemetry
- [24:40](https://www.youtube.com/watch?v=Q-oazDEucLE&t=1480s) Automating test verification and path detection
- [27:10](https://www.youtube.com/watch?v=Q-oazDEucLE&t=1630s) Approval tests and safe refactoring foundations
- [28:58](https://www.youtube.com/watch?v=Q-oazDEucLE&t=1738s) Mutation testing introduction and purpose
- [31:18](https://www.youtube.com/watch?v=Q-oazDEucLE&t=1878s) Mutation testing execution with agent automation
- [33:04](https://www.youtube.com/watch?v=Q-oazDEucLE&t=1984s) Test-driven development loop and refactoring workflow
- [34:31](https://www.youtube.com/watch?v=Q-oazDEucLE&t=2071s) Wrapper procedures and test compatibility during refactoring
- [35:45](https://www.youtube.com/watch?v=Q-oazDEucLE&t=2145s) Agent economics and cascading benefits of clean code
- [37:15](https://www.youtube.com/watch?v=Q-oazDEucLE&t=2235s) Ensuring agent compliance with instructions and hooks
- [39:23](https://www.youtube.com/watch?v=Q-oazDEucLE&t=2363s) Test setup and agent learning for refactoring
- [41:12](https://www.youtube.com/watch?v=Q-oazDEucLE&t=2472s) Code quality rules and refactoring practices
- [43:19](https://www.youtube.com/watch?v=Q-oazDEucLE&t=2599s) Debug logging and feature telemetry safety nets
- [46:28](https://www.youtube.com/watch?v=Q-oazDEucLE&t=2788s) Mutation testing with AI agents
- [48:26](https://www.youtube.com/watch?v=Q-oazDEucLE&t=2906s) Temporary vs permanent test coverage
- [50:31](https://www.youtube.com/watch?v=Q-oazDEucLE&t=3031s) Real unit tests and bug discovery in refactoring
- [52:46](https://www.youtube.com/watch?v=Q-oazDEucLE&t=3166s) Closing remarks and webinar information

## Features

| Feature | Status | At |
|---|---|---|
| AI code generation for legacy AL refactoring | status not stated | [7:17](https://www.youtube.com/watch?v=Q-oazDEucLE&t=437s) |
| Compilation as first-pass validation for AI agents | status not stated | [10:08](https://www.youtube.com/watch?v=Q-oazDEucLE&t=608s) |
| Static analysis linters for code quality | status not stated | [10:46](https://www.youtube.com/watch?v=Q-oazDEucLE&t=646s) |
| Complexity linters for procedure length control | status not stated | [11:42](https://www.youtube.com/watch?v=Q-oazDEucLE&t=702s) |
| Warning-as-errors compiler option with ruleset files | status not stated | [12:16](https://www.youtube.com/watch?v=Q-oazDEucLE&t=736s) |
| Test-driven development with AI agents | status not stated, demoed | [13:08](https://www.youtube.com/watch?v=Q-oazDEucLE&t=788s) |
| Build automation and CI/CD for agent loops | status not stated | [14:27](https://www.youtube.com/watch?v=Q-oazDEucLE&t=867s) |
| Debug logging via telemetry interception | status not stated, demoed | [21:04](https://www.youtube.com/watch?v=Q-oazDEucLE&t=1264s) |
| Observational test patterns for code discovery | status not stated, demoed | [25:49](https://www.youtube.com/watch?v=Q-oazDEucLE&t=1549s) |
| Automated path coverage verification | status not stated, demoed | [25:49](https://www.youtube.com/watch?v=Q-oazDEucLE&t=1549s) |
| Approval testing for refactoring preparation | status not stated, demoed | [27:36](https://www.youtube.com/watch?v=Q-oazDEucLE&t=1656s) |
| Mutation testing for scenario coverage verification | status not stated, demoed | [28:58](https://www.youtube.com/watch?v=Q-oazDEucLE&t=1738s) |
| Test-driven development loop in refactoring | status not stated, demoed | [33:04](https://www.youtube.com/watch?v=Q-oazDEucLE&t=1984s) |
| Wrapper procedures for safe refactoring | status not stated, demoed | [34:31](https://www.youtube.com/watch?v=Q-oazDEucLE&t=2071s) |
| Agent-assisted economics of safe refactoring | status not stated | [35:45](https://www.youtube.com/watch?v=Q-oazDEucLE&t=2145s) |
| Large language model selection for AL code | status not stated | [37:42](https://www.youtube.com/watch?v=Q-oazDEucLE&t=2262s) |
| Git hooks for agent instruction enforcement | status not stated | [38:40](https://www.youtube.com/watch?v=Q-oazDEucLE&t=2320s) |
| Tests as project documentation for agents | status not stated | [40:04](https://www.youtube.com/watch?v=Q-oazDEucLE&t=2404s) |
| AI Agent for test execution and verification | status not stated | [39:09](https://www.youtube.com/watch?v=Q-oazDEucLE&t=2349s) |
| Leave codebase better rule | status not stated | [40:49](https://www.youtube.com/watch?v=Q-oazDEucLE&t=2449s) |
| Touch code only when necessary | status not stated | [41:31](https://www.youtube.com/watch?v=Q-oazDEucLE&t=2491s) |
| AI-assisted test development playbook | status not stated | [41:52](https://www.youtube.com/watch?v=Q-oazDEucLE&t=2512s) |
| Debug logging with feature telemetry safety nets | status not stated | [44:24](https://www.youtube.com/watch?v=Q-oazDEucLE&t=2664s) |
| AI-generated mutation testing plans | status not stated | [46:28](https://www.youtube.com/watch?v=Q-oazDEucLE&t=2788s) |
| Characterization testing for legacy code | status not stated | [49:22](https://www.youtube.com/watch?v=Q-oazDEucLE&t=2962s) |
| Real unit and integration tests after refactoring | status not stated | [50:31](https://www.youtube.com/watch?v=Q-oazDEucLE&t=3031s) |
| Bug discovery during decoupling and refactoring | status not stated | [51:25](https://www.youtube.com/watch?v=Q-oazDEucLE&t=3085s) |

## AL objects mentioned

As heard in the captions. A name that matches one object page by exact type and name links to it; the others stay as named.

- other "MCP server" at [12:16](https://www.youtube.com/watch?v=Q-oazDEucLE&t=736s)
- interface "telemetry logger interface" at [22:49](https://www.youtube.com/watch?v=Q-oazDEucLE&t=1369s)
- codeunit "test telemetry logger" at [22:49](https://www.youtube.com/watch?v=Q-oazDEucLE&t=1369s)
- other "CI/CD check" at [44:58](https://www.youtube.com/watch?v=Q-oazDEucLE&t=2698s)
- other "feature telemetry" at [45:11](https://www.youtube.com/watch?v=Q-oazDEucLE&t=2711s)
- other "mutation plan" at [47:05](https://www.youtube.com/watch?v=Q-oazDEucLE&t=2825s)
- other "AL test framework" at [42:27](https://www.youtube.com/watch?v=Q-oazDEucLE&t=2547s)

Not found in BC28-30: interface "telemetry logger interface", codeunit "test telemetry logger".

## Quotes

- [5:52](https://www.youtube.com/watch?v=Q-oazDEucLE&t=352s) "This is projects that where already exist a lot of code and you are supposed to make another feature, fix a bug, do some"
- [6:09](https://www.youtube.com/watch?v=Q-oazDEucLE&t=369s) "If you are in in the same circles as I am, then there is a lot of legacy AL code."
- [7:17](https://www.youtube.com/watch?v=Q-oazDEucLE&t=437s) "We have got an AI and AI is really good at writing very very fast code and not code that uh that executes fast"
- [8:07](https://www.youtube.com/watch?v=Q-oazDEucLE&t=487s) "Every one of the things that AI actually is really good at is understanding uh the principles behind uh testdriven development writing test and"
- [10:08](https://www.youtube.com/watch?v=Q-oazDEucLE&t=608s) "Every time she makes a change ask it to compile uh the app and and that can be done nowhere you have test or"

## Disclaimers in the video

- [37:54](https://www.youtube.com/watch?v=Q-oazDEucLE&t=2274s) subject-to-change: pump instructions are big a and a models are nondeterministic
- [49:09](https://www.youtube.com/watch?v=Q-oazDEucLE&t=2949s) other: Stefan Mavan has built something for containerless test for unit test working with his AL test

Presenters (as heard): Fleming Buckson, Luke, Thorban Lat, Stefan Mavan.
