---
## Copyright (C) 2026 - 2026 ENCRYPTED SUPPORT LLC <adrelanos@whonix.org>
## See the file COPYING for copying conditions.

## AI-Assisted

## Coverage-guided D-Bus surface fuzzing for fm-shim-backend.
##
## fm-shim-backend implements org.freedesktop.FileManager1 on the
## session bus. dfuzzer (Debian-archive-shipped) walks every method
## / signal the service exposes and sends type-correct adversarial
## payloads. Catches the integration surface (D-Bus marshaling
## glue, sd_notify path, signal handlers, leaks across method
## calls) that an in-process libFuzzer harness on the parser alone
## would not catch.
##
## Trigger shape mirrors helper-scripts' local-python-fuzz.yml:
## workflow_dispatch + path-filtered pull_request. PRs that don't
## touch the shim backend, its compile script, the dfuzzer build /
## runner, or this workflow itself are skipped to keep cost bounded.
##
## Workflow body lives in ci/dfuzzer-run.sh (R-100); this file
## carries only the trigger schedule + apt install + invocation.

name: dfuzzer (D-Bus)

on:
  workflow_dispatch:
    inputs:
      seconds:
        description: 'Per-method dfuzzer time budget (seconds)'
        required: false
        default: '60'
  pull_request:
    branches: [master]
    paths:
      - 'usr/src/security-misc/fm-shim-backend.c#security-misc-shared'
      - 'usr/libexec/security-misc/compile-fm-shim-backend#security-misc-shared'
      - 'ci/dfuzzer-build.sh'
      - 'ci/dfuzzer-run.sh'
      - 'ci/codeql-prepare.sh'
      - '.github/workflows/local-dbus-fuzz.yml'

permissions:
  contents: read

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  dfuzzer:
    name: dfuzzer (org.freedesktop.FileManager1)
    runs-on: ubuntu-latest
    timeout-minutes: 20

    if: github.event.pull_request.head.repo.full_name == github.repository || github.event_name != 'pull_request'

    permissions:
      contents: read

    env:
      DFUZZER_SECONDS: ${{ inputs.seconds || '60' }}

    steps:
      - name: Checkout repository
        uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd  # v6.0.2
        with:
          persist-credentials: false

      ## install-deps composite action: apt deps for dfuzzer-build.sh
      ## (build + runtime + fm-shim backend compile) plus genmkfile +
      ## helper-scripts (org-standard install path; see
      ## ci/dfuzzer-build.sh header for per-package rationale).
      - name: Install apt deps + genmkfile + helper-scripts
        uses: org-ai-assisted/developer-meta-files/.github/actions/install-deps@master
        with:
          apt-packages: 'meson ninja-build xsltproc docbook-xsl libglib2.0-dev dbus dbus-x11 libdbus-1-dev libsystemd-dev pkg-config gcc'

      - name: Build dfuzzer from source
        ## dfuzzer is not packaged for Ubuntu 24.04; build from
        ## pinned upstream tag. See ci/dfuzzer-build.sh.
        run: ci/dfuzzer-build.sh

      - name: Prepare extension-clean source paths
        run: ci/codeql-prepare.sh

      - name: Run dfuzzer
        run: ci/dfuzzer-run.sh
