Improve Bluesky reply/quote accessibility and split test bootstrap workflow

- Fix Bluesky quoted post rendering across list output, screen-reader speech, and View Post by centralizing quote extraction.
- Add robust quote URL extraction (facets/embed/text), include quoted URLs in URL shortcuts, and append full quoted URLs when hidden/truncated.
- Improve reply context handling:
  - add and use `$reply_to` template variable,
  - hydrate missing reply target handles in home/feed items,
  - keep backward compatibility for templates that do not include `$reply_to`.
- Align Bluesky default/fallback post templates to include reply context (`$reply_to`).
- Add/extend focused Bluesky tests for quote text, quote URLs, reply context, and template fallback behavior.
- Refactor scripts:
  - add bootstrap-dev.ps1 for environment setup (submodules, venv, deps),
  - keep run-tests.ps1 focused on running tests only,
  - add PowerShell comment-based help in English.
- Update README with the new bootstrap/test workflow and examples.
This commit is contained in:
Juanjo M
2026-02-15 23:50:00 +00:00
parent abf4cb0df1
commit 6e56d94448
11 changed files with 919 additions and 35 deletions

176
scripts/bootstrap-dev.ps1 Normal file
View File

@@ -0,0 +1,176 @@
<#
.SYNOPSIS
Bootstraps a local TWBlue development environment on Windows.
.DESCRIPTION
This script initializes git submodules, creates/uses a virtual environment,
and installs Python dependencies from requirements.txt.
It is intended to be run once when starting on the repository (or whenever
you need to rebuild your local environment).
.PARAMETER RecreateVenv
Deletes and recreates the `.venv` folder before installing dependencies.
.PARAMETER UpgradePip
Upgrades `pip`, `setuptools`, and `wheel` before installing requirements.
.PARAMETER SkipSubmodules
Skips `git submodule init` and `git submodule update --recursive`.
.PARAMETER SystemPython
Uses a detected system Python instead of creating/using `.venv`.
.EXAMPLE
./scripts/bootstrap-dev.ps1
.EXAMPLE
./scripts/bootstrap-dev.ps1 -RecreateVenv -UpgradePip
.EXAMPLE
./scripts/bootstrap-dev.ps1 -SystemPython -SkipSubmodules
#>
param(
[switch]$RecreateVenv,
[switch]$UpgradePip,
[switch]$SkipSubmodules,
[switch]$SystemPython
)
$ErrorActionPreference = "Stop"
function Write-Step {
param([string]$Message)
Write-Host "==> $Message" -ForegroundColor Cyan
}
function Resolve-RepoRoot {
param([string]$ScriptDir)
return (Resolve-Path (Join-Path $ScriptDir "..")).Path
}
function Test-PythonCandidate {
param(
[string]$Exe,
[string[]]$BaseArgs = @()
)
try {
& $Exe @BaseArgs -c "import sys; print(sys.version)" | Out-Null
return ($LASTEXITCODE -eq 0)
}
catch {
return $false
}
}
function New-PythonSpec {
param(
[string]$Exe,
[string[]]$BaseArgs = @()
)
return [pscustomobject]@{
Exe = $Exe
BaseArgs = $BaseArgs
}
}
function Get-PythonSpec {
param([string]$RepoRoot, [bool]$UseSystemPython)
if (-not $UseSystemPython) {
$venvPython = Join-Path $RepoRoot ".venv\Scripts\python.exe"
if (Test-Path $venvPython) {
return (New-PythonSpec -Exe $venvPython)
}
}
$candidates = @()
$pythonCmd = Get-Command python -ErrorAction SilentlyContinue
if ($pythonCmd) {
$candidates += ,(New-PythonSpec -Exe "python")
}
$pyCmd = Get-Command py -ErrorAction SilentlyContinue
if ($pyCmd) {
$candidates += ,(New-PythonSpec -Exe "py" -BaseArgs @("-3.10"))
$candidates += ,(New-PythonSpec -Exe "py" -BaseArgs @("-3"))
}
foreach ($candidate in $candidates) {
if (Test-PythonCandidate -Exe $candidate.Exe -BaseArgs $candidate.BaseArgs) {
return $candidate
}
}
throw "Could not find a usable Python. Install Python 3.10+ and try again."
}
function Invoke-Python {
param(
[pscustomobject]$PythonSpec,
[string[]]$Arguments,
[string]$WorkingDirectory
)
Push-Location $WorkingDirectory
try {
& $PythonSpec.Exe @($PythonSpec.BaseArgs + $Arguments)
if ($LASTEXITCODE -ne 0) {
throw "Python command failed with exit code $LASTEXITCODE"
}
}
finally {
Pop-Location
}
}
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$repoRoot = Resolve-RepoRoot -ScriptDir $scriptDir
Write-Step "Repository: $repoRoot"
if (-not $SkipSubmodules) {
$gitCmd = Get-Command git -ErrorAction SilentlyContinue
if ($gitCmd) {
Write-Step "Initializing/updating submodules"
Push-Location $repoRoot
try {
& git submodule init | Out-Host
& git submodule update --recursive | Out-Host
}
finally {
Pop-Location
}
}
else {
Write-Warning "Git is not available. Skipping submodule initialization."
}
}
$venvPath = Join-Path $repoRoot ".venv"
if ($RecreateVenv -and (Test-Path $venvPath)) {
Write-Step "Removing existing virtual environment"
Remove-Item -Recurse -Force $venvPath
}
if (-not $SystemPython -and -not (Test-Path (Join-Path $venvPath "Scripts\python.exe"))) {
Write-Step "Creating virtual environment in .venv"
$bootstrapPython = Get-PythonSpec -RepoRoot $repoRoot -UseSystemPython $true
Invoke-Python -PythonSpec $bootstrapPython -Arguments @("-m", "venv", ".venv") -WorkingDirectory $repoRoot
}
$python = Get-PythonSpec -RepoRoot $repoRoot -UseSystemPython $SystemPython.IsPresent
Write-Step "Using Python: $($python.Exe) $($python.BaseArgs -join ' ')"
if ($UpgradePip) {
Write-Step "Upgrading pip/setuptools/wheel"
Invoke-Python -PythonSpec $python -Arguments @("-m", "pip", "install", "--upgrade", "pip", "setuptools", "wheel") -WorkingDirectory $repoRoot
}
Write-Step "Installing dependencies"
Invoke-Python -PythonSpec $python -Arguments @("-m", "pip", "install", "-r", "requirements.txt") -WorkingDirectory $repoRoot
Write-Step "Bootstrap completed"

163
scripts/run-tests.ps1 Normal file
View File

@@ -0,0 +1,163 @@
<#
.SYNOPSIS
Runs TWBlue tests with minimal runtime setup.
.DESCRIPTION
This script only executes pytest. It does not install dependencies,
create virtual environments, or initialize submodules.
Use `./scripts/bootstrap-dev.ps1` first to prepare a development environment.
.PARAMETER PytestTargets
One or more pytest target paths/files. Defaults to `src/test`.
.PARAMETER PytestArgs
Additional pytest arguments. Defaults to `-q`.
.PARAMETER SystemPython
Uses a detected system Python instead of `.venv`.
.EXAMPLE
./scripts/run-tests.ps1
.EXAMPLE
./scripts/run-tests.ps1 -PytestTargets src/test/sessions/blueski -PytestArgs "-q"
.EXAMPLE
./scripts/run-tests.ps1 -SystemPython
#>
param(
[string[]]$PytestTargets = @("src/test"),
[string[]]$PytestArgs = @("-q"),
[switch]$SystemPython
)
$ErrorActionPreference = "Stop"
function Write-Step {
param([string]$Message)
Write-Host "==> $Message" -ForegroundColor Cyan
}
function Resolve-RepoRoot {
param([string]$ScriptDir)
return (Resolve-Path (Join-Path $ScriptDir "..")).Path
}
function Test-PythonCandidate {
param(
[string]$Exe,
[string[]]$BaseArgs = @()
)
try {
& $Exe @BaseArgs -c "import sys; print(sys.version)" | Out-Null
return ($LASTEXITCODE -eq 0)
}
catch {
return $false
}
}
function New-PythonSpec {
param(
[string]$Exe,
[string[]]$BaseArgs = @()
)
return [pscustomobject]@{
Exe = $Exe
BaseArgs = $BaseArgs
}
}
function Get-PythonSpec {
param([string]$RepoRoot, [bool]$UseSystemPython)
if (-not $UseSystemPython) {
$venvPython = Join-Path $RepoRoot ".venv\Scripts\python.exe"
if (Test-Path $venvPython) {
return (New-PythonSpec -Exe $venvPython)
}
}
$candidates = @()
$pythonCmd = Get-Command python -ErrorAction SilentlyContinue
if ($pythonCmd) {
$candidates += ,(New-PythonSpec -Exe "python")
}
$pyCmd = Get-Command py -ErrorAction SilentlyContinue
if ($pyCmd) {
$candidates += ,(New-PythonSpec -Exe "py" -BaseArgs @("-3.10"))
$candidates += ,(New-PythonSpec -Exe "py" -BaseArgs @("-3"))
}
foreach ($candidate in $candidates) {
if (Test-PythonCandidate -Exe $candidate.Exe -BaseArgs $candidate.BaseArgs) {
return $candidate
}
}
throw "Could not find a usable Python. Install Python 3.10+ and try again."
}
function Invoke-Python {
param(
[pscustomobject]$PythonSpec,
[string[]]$Arguments,
[string]$WorkingDirectory
)
Push-Location $WorkingDirectory
try {
& $PythonSpec.Exe @($PythonSpec.BaseArgs + $Arguments)
if ($LASTEXITCODE -ne 0) {
throw "Python command failed with exit code $LASTEXITCODE"
}
}
finally {
Pop-Location
}
}
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$repoRoot = Resolve-RepoRoot -ScriptDir $scriptDir
Write-Step "Repository: $repoRoot"
$venvPython = Join-Path $repoRoot ".venv\Scripts\python.exe"
if (-not $SystemPython -and -not (Test-Path $venvPython)) {
throw "No .venv Python found. Run ./scripts/bootstrap-dev.ps1 first, or pass -SystemPython."
}
$python = Get-PythonSpec -RepoRoot $repoRoot -UseSystemPython $SystemPython.IsPresent
Write-Step "Using Python: $($python.Exe) $($python.BaseArgs -join ' ')"
Write-Step "Detecting Python architecture"
$archOutput = & $python.Exe @($python.BaseArgs + @("-c", "import struct; print('x64' if struct.calcsize('P')*8 == 64 else 'x86')"))
if ($LASTEXITCODE -ne 0 -or -not $archOutput) {
throw "Could not determine Python architecture."
}
$arch = ($archOutput | Select-Object -Last 1).Trim()
if ($arch -ne "x86" -and $arch -ne "x64") {
throw "Could not determine Python architecture (result: '$arch')."
}
$vlcPath = Join-Path $repoRoot "windows-dependencies\$arch"
if (-not (Test-Path $vlcPath)) {
throw "Could not find '$vlcPath'. Run ./scripts/bootstrap-dev.ps1 first."
}
$env:PYTHON_VLC_MODULE_PATH = $vlcPath
if (-not ($env:PATH -split ';' | Where-Object { $_ -eq $vlcPath })) {
$env:PATH = "$vlcPath;$env:PATH"
}
Write-Step "PYTHON_VLC_MODULE_PATH=$($env:PYTHON_VLC_MODULE_PATH)"
Write-Step "Running tests"
$pytestCommandArgs = @("-m", "pytest") + $PytestTargets + $PytestArgs
Invoke-Python -PythonSpec $python -Arguments $pytestCommandArgs -WorkingDirectory $repoRoot