google/tachometer

"root" configuration is not used when resolving a benchmark's URL

cdata opened this issue · 2 comments

cdata commented

When configuring a basic Tachometer benchmark, I created a directory structure like this:

project_root/
 ⮑ benchmarks/
     ⮑ tutorial.html
 ⮑ tachometer.json

And a configuration file for Tachometer that looked like this:

{
  "root": "./benchmarks",
  "benchmarks": [
    {
      "name": "Tutorial Benchmark",
      "url": "./tutorial.html"
    }
  ]
}

The result I got from doing this was initially surprising:

❯ tach --config ./tachometer.json 
Error: File or directory is not accessible from server root: ./tutorial.html
    at Object.urlFromLocalPath (/Users/cdata/repositories/github.com/cdata/tach-test-repo/node_modules/tachometer/src/config.ts:179:11)
    at parseBenchmark (/Users/cdata/repositories/github.com/cdata/tach-test-repo/node_modules/tachometer/src/configfile.ts:385:24)
    at Object.parseConfigFile (/Users/cdata/repositories/github.com/cdata/tach-test-repo/node_modules/tachometer/src/configfile.ts:290:43)
    at Object.makeConfig (/Users/cdata/repositories/github.com/cdata/tach-test-repo/node_modules/tachometer/src/config.ts:90:38)
    at realMain (/Users/cdata/repositories/github.com/cdata/tach-test-repo/node_modules/tachometer/src/cli.ts:113:18)
    at Object.main (/Users/cdata/repositories/github.com/cdata/tach-test-repo/node_modules/tachometer/src/cli.ts:40:15)

I had assumed that whatever "url" I used would be resolved from the configured "root". However, when I changed my configuration to look like this:

{
  "root": "./benchmarks",
  "benchmarks": [
    {
      "name": "Tutorial Benchmark",
      "url": "./benchmarks/tutorial.html"
    }
  ]
}

Everything suddenly worked. My conclusion was that either I used the "root" configuration incorrectly, or else it is being ignored and this is a bug.

This may be working as intended. If that is the case, the documentation could possibly be improved to better explain the meaning and correct use of the "root" configuration option.

I think I agree that it makes more sense for urls to be relative to the root, if there is one. Probably just an oversight.

A related question is what the root itself is relative to (and what a url without a root is relative to). I think it should be relative to the location of the config file, but I have a feeling it's currently relative to the cwd of the tachometer process? WDYT?

cdata commented

A related question is what the root itself is relative to (and what a url without a root is relative to). I think it should be relative to the location of the config file, but I have a feeling it's currently relative to the cwd of the tachometer process? WDYT?

@aomarks this might work fine if you intend the user to have multiple configuration files for the condition where there are multiple roots in a project. I usually expect a process to assume the current working directory is my intended basis for relative paths, and Tachometer doesn't require a configuration file to be used, so it might not be the most reliable signal.

Reflecting a little on my original issue, the thing that tripped me up the most was the error message: Error: File or directory is not accessible from server root: ./tutorial.html

"root" is being used with a possibly different definition there.