Skip to content

Add test suite and CI workflow#13

Open
Copilot wants to merge 18 commits intomainfrom
copilot/add-tests-for-functions
Open

Add test suite and CI workflow#13
Copilot wants to merge 18 commits intomainfrom
copilot/add-tests-for-functions

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 2, 2026

✅ Completed: Add Tests and CI Workflow

All tasks have been successfully completed:

  • Create test file src/lib_test.ts with 42 comprehensive tests for core functions:
    • Test findClosestRationalAngle() function (7 tests)
    • Test gcd() function (7 tests)
    • Test lcm() function (5 tests)
    • Test calculateTileDimensions() function (6 tests)
    • Test validateDimensions() function (9 tests)
    • Test getOutputPath() function (5 tests)
    • Test RATIONAL_ANGLES constant (5 tests)
  • Create GitHub Actions workflow file .github/workflows/test.yml to run tests on PRs
  • Add test task to deno.json for easy test execution
  • Add .gitignore to exclude build artifacts and test outputs
  • Update README with testing instructions
  • Address code review feedback
  • Fix security vulnerabilities (add explicit permissions to workflow)
  • Remove master branch from CI workflow (only main branch)
  • Add --allow-env flag to fix Sharp library initialization error
  • Add --allow-ffi flag to allow Sharp native bindings to load
  • Fix test failures: normalize angles to -180/180 range and prevent duplicate errors for infinity
  • Fix formatting and linting issues (remove unused imports)
  • Fix typos in README documentation
  • Apply code review feedback:
    • Remove unnecessary --allow-write permission from test task
    • Fix "pseudoelements" → "pseudo-elements" typos (2 instances)
    • Fix grammar "example. this" → "example, this"
    • Fix grammar "tile produces" → "tile produced"
    • Use join() for cross-platform path handling in getOutputPath()
    • Add @std/assert to deno.json imports for proper linting
    • Use SEPARATOR constant for proper cross-platform path prefix handling (`./ on POSIX, .\ on Windows)
    • Make path tests platform-agnostic using join() and SEPARATOR
    • Add specific expected values to calculateTileDimensions() tests (141x141 for 45° on 100x100, 447x224 for 26.565° on 100x200)
Original prompt

This section details on the original issue you should resolve

<issue_title>Add tests</issue_title>
<issue_description>We need to add tests to these functions and make sure CI runs them on each PR using github workflows.</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 4 commits March 2, 2026 18:06
Co-authored-by: marlonmarcello <1956448+marlonmarcello@users.noreply.github.com>
Co-authored-by: marlonmarcello <1956448+marlonmarcello@users.noreply.github.com>
Co-authored-by: marlonmarcello <1956448+marlonmarcello@users.noreply.github.com>
Co-authored-by: marlonmarcello <1956448+marlonmarcello@users.noreply.github.com>
Copilot AI changed the title [WIP] Add tests for functions and CI integration Add test suite and CI workflow Mar 2, 2026
@marlonmarcello marlonmarcello requested a review from liamegan March 3, 2026 01:49
@marlonmarcello
Copy link
Copy Markdown
Member

@copilot you can remove the master branch from the list in CI, also, we are getting the following error:

./src/lib_test.ts (uncaught error)
error: (in promise) NotCapable: Requires env access to "npm_package_config_libvips", run again with the --allow-env flag
const minimumLibvipsVersionLabelled = process.env.npm_package_config_libvips || config.libvips;
                                                  ^
    at Object.getEnv [as get] (ext:deno_os/30_os.js:124:10)
    at denoEnvGet (ext:deno_node/_process/process.ts:30:21)
    at Object.get (ext:deno_node/_process/process.ts:47:22)
    at file:///home/runner/.cache/deno/npm/registry.npmjs.org/sharp/0.34.5/lib/libvips.js:16:51
    at Object.<anonymous> (file:///home/runner/.cache/deno/npm/registry.npmjs.org/sharp/0.34.5/lib/libvips.js:209:3)
    at Module._compile (node:module:759:34)
    at loadMaybeCjs (node:module:784:10)
    at Object.Module._extensions..js (node:module:769:12)
    at Module.load (node:module:677:32)
    at Module._load (node:module:535:12)
This error was not caught from a test and caused the test runner to fail on the referenced module.
It most likely originated from a dangling promise, event/timeout handler or top-level code.

 FAILURES 

./src/lib_test.ts (uncaught error)

FAILED | 0 passed | 1 failed (0ms)

error: Test failed

Co-authored-by: marlonmarcello <1956448+marlonmarcello@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 3, 2026

@copilot you can remove the master branch from the list in CI, also, we are getting the following error:

./src/lib_test.ts (uncaught error)

...

Fixed in commit ce42c01. Removed master branch from the workflow and added --allow-env flag to the test command to allow Sharp to access the required environment variables during initialization.

@marlonmarcello
Copy link
Copy Markdown
Member

@copilot looks like we are missing sharp. Does CI install the correct deps?

Check src/lib_test.ts
Uncaught error from ./src/lib_test.ts FAILED

 ERRORS 

./src/lib_test.ts (uncaught error)
error: (in promise) Error: Could not load the "sharp" module using the linux-x64 runtime
undefined: Requires ffi access to "/home/runner/.cache/deno/npm/registry.npmjs.org/@img/sharp-linux-x64/0.34.5/lib/sharp-linux-x64.node", run again with the --allow-ffi flag
Possible solutions:
- Ensure optional dependencies can be installed:
    npm install --include=optional sharp
- Ensure your package manager supports multi-platform installation:
    See https://sharp.pixelplumbing.com/install#cross-platform
- Add platform-specific dependencies:
    npm install --os=linux --cpu=x64 sharp
- Consult the installation documentation:
    See https://sharp.pixelplumbing.com/install
  throw new Error(help.join('\n'));
        ^
    at file:///home/runner/.cache/deno/npm/registry.npmjs.org/sharp/0.34.5/lib/sharp.js:120:9
    at Object.<anonymous> (file:///home/runner/.cache/deno/npm/registry.npmjs.org/sharp/0.34.5/lib/sharp.js:123:3)
    at Module._compile (node:module:759:34)
    at loadMaybeCjs (node:module:784:10)
    at Object.Module._extensions..js (node:module:769:12)
    at Module.load (node:module:677:32)
    at Module._load (node:module:535:12)
    at Module.require (node:module:696:19)
    at require (node:module:830:16)
    at file:///home/runner/.cache/deno/npm/registry.npmjs.org/sharp/0.34.5/lib/constructor.js:10:1
This error was not caught from a test and caused the test runner to fail on the referenced module.
It most likely originated from a dangling promise, event/timeout handler or top-level code.

 FAILURES 

./src/lib_test.ts (uncaught error)

FAILED | 0 passed | 1 failed (0ms)

error: Test failed

Co-authored-by: marlonmarcello <1956448+marlonmarcello@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 3, 2026

@copilot looks like we are missing sharp. Does CI install the correct deps?

Check src/lib_test.ts

...

Fixed in commit 44f2b90. Added --allow-ffi flag to allow Sharp to load its native bindings. Deno automatically installs npm dependencies from the imports in deno.json, so Sharp will be installed when tests run in CI.

@marlonmarcello
Copy link
Copy Markdown
Member

@copilot we've got 3 failed tests


 ERRORS 

findClosestRationalAngle - normalizes negative angles => ./src/lib_test.ts:49:6
error: AssertionError: Values are not equal.


    [Diff] Actual / Expected


-   90
+   -45

  throw new AssertionError(message);
        ^
    at assertEquals (https://jsr.io/@std/assert/1.0.19/equals.ts:67:9)
    at file:///home/runner/work/wtc-tile-maker/wtc-tile-maker/src/lib_test.ts:51:3

validateDimensions - rejects infinite width => ./src/lib_test.ts:212:6
error: AssertionError: Values are not equal.


    [Diff] Actual / Expected


-   2
+   1

  throw new AssertionError(message);
        ^
    at assertEquals (https://jsr.io/@std/assert/1.0.19/equals.ts:67:9)
    at file:///home/runner/work/wtc-tile-maker/wtc-tile-maker/src/lib_test.ts:218:3

validateDimensions - rejects infinite height => ./src/lib_test.ts:222:6
error: AssertionError: Values are not equal.


    [Diff] Actual / Expected


-   2
+   1

  throw new AssertionError(message);
        ^
    at assertEquals (https://jsr.io/@std/assert/1.0.19/equals.ts:67:9)
    at file:///home/runner/work/wtc-tile-maker/wtc-tile-maker/src/lib_test.ts:228:3

 FAILURES 

findClosestRationalAngle - normalizes negative angles => ./src/lib_test.ts:49:6
validateDimensions - rejects infinite width => ./src/lib_test.ts:212:6
validateDimensions - rejects infinite height => ./src/lib_test.ts:222:6

FAILED | 39 passed | 3 failed (14ms)

error: Test failed

… infinity errors

Co-authored-by: marlonmarcello <1956448+marlonmarcello@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 3, 2026

@copilot we've got 3 failed tests


...

Fixed in commit 0ba863e. The failures were due to:

  1. findClosestRationalAngle() was normalizing angles to 0-360 range, but should normalize to -180 to 180 to match the RATIONAL_ANGLES entries
  2. validateDimensions() was producing duplicate errors for infinity (both infinity check and size check triggered) - now returns early after detecting infinity

@marlonmarcello
Copy link
Copy Markdown
Member

@copilot looks like tests are passing now but not formatting or linting, make sure you run those every time.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 8 changed files in this pull request and generated 6 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread deno.json Outdated
Comment thread README.md Outdated
Comment thread README.md
Comment thread README.md Outdated
Comment thread README.md Outdated
Comment thread src/lib.ts Outdated
Co-authored-by: marlonmarcello <1956448+marlonmarcello@users.noreply.github.com>
@marlonmarcello
Copy link
Copy Markdown
Member

@copilot looks like the last update changed the expected path, the test is failing:

 ERRORS 
getOutputPath - handles files in current directory => ./src/lib_test.ts:268:6
error: AssertionError: Values are not equal.
    [Diff] Actual / Expected
-   image-tile-90.png
+   ./image-tile-90.png

  throw new AssertionError(message);
        ^
    at assertEquals (https://jsr.io/@std/assert/1.0.19/equals.ts:67:9)
    at file:///home/runner/work/wtc-tile-maker/wtc-tile-maker/src/lib_test.ts:273:3
 FAILURES 
getOutputPath - handles files in current directory => ./src/lib_test.ts:268:6
FAILED | 41 passed | 1 failed (13ms)
error: Test failed

Co-authored-by: marlonmarcello <1956448+marlonmarcello@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 4, 2026

@copilot looks like the last update changed the expected path, the test is failing:

 ERRORS 

...

Fixed in commit 3d1197d. The join() function was removing the ./ prefix for files in the current directory. Updated getOutputPath() to explicitly preserve the ./ prefix when dirname() returns "." while still using join() for cross-platform compatibility on other paths.

@marlonmarcello marlonmarcello requested a review from Copilot March 4, 2026 01:13
@marlonmarcello marlonmarcello marked this pull request as ready for review March 4, 2026 01:13
@marlonmarcello
Copy link
Copy Markdown
Member

@copilot looks like the last update changed the expected path, the test is failing:

 ERRORS 

...

Fixed in commit 3d1197d. The join() function was removing the ./ prefix for files in the current directory. Updated getOutputPath() to explicitly preserve the ./ prefix when dirname() returns "." while still using join() for cross-platform compatibility on other paths.

@copilot the return is now return inputDir === "." ? ./${outputFileName} : outputPath;, it seems that you hard coded ./, didn't we update to use join() so that we explicitly avoided that so we could support windows? Wouldn't hard coding like this break it?

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 8 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/lib_test.ts
Comment thread src/lib_test.ts
@marlonmarcello
Copy link
Copy Markdown
Member

@copilot apply changes based on the comments in this thread

Co-authored-by: marlonmarcello <1956448+marlonmarcello@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 4, 2026

@copilot looks like the last update changed the expected path, the test is failing:

 ERRORS 

...

You're absolutely right! Fixed in commit 97bb6da. The hardcoded ./ would break on Windows where the separator is \. Now using SEPARATOR constant from @std/path which automatically uses / on POSIX systems (Linux, macOS) and \ on Windows. The code now properly generates ./file.png on POSIX and .\file.png on Windows.

…eTileDimensions

Co-authored-by: marlonmarcello <1956448+marlonmarcello@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 4, 2026

@copilot apply changes based on the comments in this thread

Fixed in commit 83130e2:

  • Made path tests platform-agnostic by using join() from @std/path to construct expected paths instead of hardcoded / separators
  • Used SEPARATOR constant for the current directory test case (.${SEPARATOR} produces ./ on POSIX, .\ on Windows)
  • Added specific expected dimensions to calculateTileDimensions() tests: 141x141 for 45° on 100x100 image, and 447x224 for 26.565° on 100x200 image

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 8 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread .github/workflows/test.yml Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add tests

3 participants