opticdev / optic

OpenAPI linting, diffing and testing. Optic helps prevent breaking changes, publish accurate documentation and improve the design of your APIs.
https://useoptic.com
MIT License
1.35k stars 79 forks source link

[issue]: api status, api spec commands do not open browser on Windows #1148

Closed affeldt28 closed 2 years ago

affeldt28 commented 2 years ago

Hey there,

if I run api status --review nothing happens, also not with api spec. Is there any verbose option or a log I could check to figure out the problem?

LouManglass commented 2 years ago

Hi @affeldt28 ,

sorry for the delay - I was away from the desk for a bit. In both cases, with the latest Optic version, I'd expect the web browser to launch. The former should take you to your local diffs page (http://localhost:34444/apis/1/diffs if running) and the latter to the documentation page (http://localhost:34444/apis/1/documentation). I wouldn't expect any command line output unless there's an error.

Would you please let us know:

affeldt28 commented 2 years ago

When i use api start i can access the page (http://localhost:34444/apis/1/diffs). I found out that when I strg+c out of api start the webserver isn't closing, so it's still occupying the port. When I now kill the process manually and start api spec, it will start the webserver. It will just not open the browser, neither a console output that it's up and running. And after the command finishes automatically, the webserver is still open.

  1. api --version

    @useoptic/cli/10.3.0 win32-x64 node-v16.13.0
  2. Windows 10 (21H1) using powershell primarily, but also tried these comands with the git-bash

  3. DEBUG=* api spec

    @oclif/config reading core plugin C:\Users\marvin\AppData\Roaming\npm\node_modules\@useoptic\cli +0ms
    @oclif/config loadJSON C:\Users\marvin\AppData\Roaming\npm\node_modules\@useoptic\cli\package.json +0ms
    @oclif/config loadJSON C:\Users\marvin\AppData\Roaming\npm\node_modules\@useoptic\cli\oclif.manifest.json +2ms
    @oclif/config:@useoptic/cli using manifest from C:\Users\marvin\AppData\Roaming\npm\node_modules\@useoptic\cli\oclif.manifest.json +0ms
    @oclif/config reading user plugins pjson C:\Users\marvin\AppData\Local\@useoptic\cli\package.json +0ms
    @oclif/config loadJSON C:\Users\marvin\AppData\Local\@useoptic\cli\package.json +2ms
    @oclif/config loading plugins [ '@oclif/plugin-help' ] +0ms
    @oclif/config reading core plugin C:\Users\marvin\AppData\Roaming\npm\node_modules\@useoptic\cli\node_modules\@oclif\plugin-help +0ms
    @oclif/config loadJSON C:\Users\marvin\AppData\Roaming\npm\node_modules\@useoptic\cli\node_modules\@oclif\plugin-help\package.json +2ms
    @oclif/config loadJSON C:\Users\marvin\AppData\Roaming\npm\node_modules\@useoptic\cli\node_modules\@oclif\plugin-help\oclif.manifest.json +1ms
    @oclif/config:@oclif/plugin-help using manifest from C:\Users\marvin\AppData\Roaming\npm\node_modules\@useoptic\cli\node_modules\@oclif\plugin-help\oclif.manifest.json +0ms
    @oclif/config config done +4ms
    @oclif/config start init hook +1ms
    @oclif/config init hook done +0ms
    api init version: @oclif/command@1.8.7 argv: [ 'spec' ] +0ms
    @oclif/config runCommand spec [] +4ms
    @oclif/config:@useoptic/cli require C:\Users\marvin\AppData\Roaming\npm\node_modules\@useoptic\cli\lib\commands\spec.js +13ms
    portfinder:defaultHosts exports._defaultHosts is: [ '0.0.0.0', '2a02:908:1761:6420::b893', '2a02:908:1761:6420:c:57cb:a47d:295d', '2a02:908:1761:6420:7987:ff6:5555:a242', 'fe80::c:57cb:a47d:22.168.0.161', 'fe80::9d5a:c724:ba76:b19b', '192.168.2.215', 'fe80::407e:ff7a:d837:b8e0', '192.168.137.1', '::1', '127.0.0.1', null ] +0ms
    @oclif/config start prerun hook +2s
    @oclif/config prerun hook done +0ms
    api:spec init version: @oclif/command@1.8.7 argv: [] +0ms
    DeprecationWarning: The _stream_wrap module is deprecated. 
    at node:_stream_wrap:4:9
    at NativeModule.compileForInternalLoader (node:internal/bootstrap/loaders:312:7)
    at NativeModule.compileForPublicLoader (node:internal/bootstrap/loaders:252:10)
    at loadNativeModule (node:internal/modules/cjs/helpers:49:9)
    at Function.Module._load (node:internal/modules/cjs/loader:804:15)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (C:\Users\marvin\AppData\Roaming\npm\node_modules\@useoptic\cli\node_modules\@httptoolkit\httpolyglot\dist\index.js:8:23)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    DeprecationWarning: The _stream_wrap module is deprecated.
    at node:_stream_wrap:4:9
    at NativeModule.compileForInternalLoader (node:internal/bootstrap/loaders:312:7)
    at NativeModule.compileForPublicLoader (node:internal/bootstrap/loaders:252:10)
    at loadNativeModule (node:internal/modules/cjs/helpers:49:9)
    at Function.Module._load (node:internal/modules/cjs/loader:804:15)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (C:\Users\marvin\AppData\Roaming\npm\node_modules\@useoptic\cli\node_modules\@httptoolkit\httpolyglot\dist\index.js:8:23)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    follow-redirects options {
    maxRedirects: 21,
    maxBodyLength: 10485760,
    protocol: 'https:',
    path: '/v1/batch',
    method: 'POST',
    headers: {
    Accept: 'application/json, text/plain, */*',
    'Content-Type': 'application/json',
    'user-agent': 'analytics-node/3.5.0',
    'Content-Length': 366
    },
    agent: undefined,
    agents: { http: undefined, https: undefined },
    auth: 'RvYGmY1bZqlbMukS8pP9DPEifG6CEBEs:',
    hostname: 'api.segment.io',
    port: null,
    nativeProtocols: {
    'http:': {
      _connectionListener: [Function: connectionListener],
      METHODS: [Array],
      STATUS_CODES: [Object],
      Agent: [Function],
      ClientRequest: [Function: ClientRequest],
      IncomingMessage: [Function: IncomingMessage],
      OutgoingMessage: [Function: OutgoingMessage],
      Server: [Function: Server],
      ServerResponse: [Function: ServerResponse],
      createServer: [Function: createServer],
      validateHeaderName: [Function: __node_internal_],
      validateHeaderValue: [Function: __node_internal_],
      get: [Function: get],
      request: [Function: request],
      maxHeaderSize: [Getter],
      globalAgent: [Getter/Setter]
    },
    'https:': {
      Agent: [Function: Agent],
      globalAgent: [Agent],
      Server: [Function: Server],
      createServer: [Function: createServer],
      get: [Function: get],
      request: [Function: request]
    }
    }
    } +0ms
    optic-debug {
    optic-debug   cwd: 'C:\\Users\\marvin\\development\\project\\em\\eventmanager-api',
    \eventmanager-api\\.optic\\api',
    optic-debug   specStorePath: 'C:\\Users\\marvin\\development\\project\\em\\eventmanager-api\\.optic\\api\\specification.json',
    optic-debug   exampleRequestsPath: 'C:\\Users\\marvin\\development\\project\\em\\eventmanager-api\\.optic\\api\\example-requests',
    optic-debug   testingConfigPath: 'C:\\Users\\marvin\\development\\project\\em\\eventmanager-api\\.optic\\testing.json'
    optic-debug } +0ms
    optic-debug { isLocked: true } +6ms
    optic-debug checking port 34444 and pid 22472 +2ms
    optic-debug the lockfile seems accurate +31ms
    optic-debug trying to read lockfile contents +0ms
    optic-debug lockfile contents: {"port":34444,"pid":22472} +1ms
    optic-debug api base url: http://localhost:34444/api +0ms
    optic-debug {
    optic-debug   cliSession: {
    optic-debug     session: {
    optic-debug       id: '1',
    optic-debug       path: 'C:\\Users\\marvin\\development\\project\\em\\eventmanager-api'
    optic-debug     }
    optic-debug   }
    optic-debug } +8ms

    and here the output when port isn't ocupied

    @oclif/config reading core plugin C:\Users\marvin\AppData\Roaming\npm\node_modules\@useoptic\cli +0ms
    @oclif/config loadJSON C:\Users\marvin\AppData\Roaming\npm\node_modules\@useoptic\cli\package.json +0ms
    @oclif/config loadJSON C:\Users\marvin\AppData\Roaming\npm\node_modules\@useoptic\cli\oclif.manifest.json +3ms
    @oclif/config:@useoptic/cli using manifest from C:\Users\marvin\AppData\Roaming\npm\node_modules\@useoptic\cli\oclif.manifest.json +0ms
    @oclif/config reading user plugins pjson C:\Users\marvin\AppData\Local\@useoptic\cli\package.json +0ms
    @oclif/config loadJSON C:\Users\marvin\AppData\Local\@useoptic\cli\package.json +2ms
    @oclif/config loading plugins [ '@oclif/plugin-help' ] +1ms
    @oclif/config reading core plugin C:\Users\marvin\AppData\Roaming\npm\node_modules\@useoptic\cli\node_modules\@oclif\plugin-help +0ms
    @oclif/config loadJSON C:\Users\marvin\AppData\Roaming\npm\node_modules\@useoptic\cli\node_modules\@oclif\plugin-help\package.json +3ms
    @oclif/config loadJSON C:\Users\marvin\AppData\Roaming\npm\node_modules\@useoptic\cli\node_modules\@oclif\plugin-help\oclif.manifest.json +1ms
    @oclif/config:@oclif/plugin-help using manifest from C:\Users\marvin\AppData\Roaming\npm\node_modules\@useoptic\cli\node_modules\@oclif\plugin-help\oclif.manifest.json +0ms
    @oclif/config config done +4ms
    @oclif/config start init hook +1ms
    @oclif/config init hook done +1ms
    api init version: @oclif/command@1.8.7 argv: [ 'spec' ] +0ms
    @oclif/config runCommand spec [] +4ms
    @oclif/config:@useoptic/cli require C:\Users\marvin\AppData\Roaming\npm\node_modules\@useoptic\cli\lib\commands\spec.js +16ms
    portfinder:defaultHosts exports._defaultHosts is: [ '0.0.0.0', '2a02:908:1761:6420::b893', '2a02:908:1761:6420:c:57cb:a47d:295d', '2a02:908:1761:6420:7987:ff6:5555:a242', 'fe80::c:57cb:a47d:295d', '192.168.0.161', 'fe80::9d5a:c724:ba76:b19b', '192.168.2.215', 'fe80::407e:ff7a:d837:b8e0', '192.168.137.1', '::1', '127.0.0.1', null ] +0ms
    @oclif/config start prerun hook +2s
    @oclif/config prerun hook done +1ms
    api:spec init version: @oclif/command@1.8.7 argv: [] +0ms
    DeprecationWarning: The _stream_wrap module is deprecated.
    at node:_stream_wrap:4:9
    at NativeModule.compileForInternalLoader (node:internal/bootstrap/loaders:312:7)
    at NativeModule.compileForPublicLoader (node:internal/bootstrap/loaders:252:10)
    at loadNativeModule (node:internal/modules/cjs/helpers:49:9)
    at Function.Module._load (node:internal/modules/cjs/loader:804:15)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (C:\Users\marvin\AppData\Roaming\npm\node_modules\@useoptic\cli\node_modules\@httptoolkit\httpolyglot\dist\index.js:8:23)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    DeprecationWarning: The _stream_wrap module is deprecated.
    at node:_stream_wrap:4:9
    at NativeModule.compileForInternalLoader (node:internal/bootstrap/loaders:312:7)
    at NativeModule.compileForPublicLoader (node:internal/bootstrap/loaders:252:10)
    at loadNativeModule (node:internal/modules/cjs/helpers:49:9)
    at Function.Module._load (node:internal/modules/cjs/loader:804:15)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (C:\Users\marvin\AppData\Roaming\npm\node_modules\@useoptic\cli\node_modules\@httptoolkit\httpolyglot\dist\index.js:8:23)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    follow-redirects options {
    maxRedirects: 21,
    maxBodyLength: 10485760,
    protocol: 'https:',
    path: '/v1/batch',
    method: 'POST',
    headers: {
    Accept: 'application/json, text/plain, */*',
    'Content-Type': 'application/json',
    'user-agent': 'analytics-node/3.5.0',
    'Content-Length': 366
    },
    agent: undefined,
    agents: { http: undefined, https: undefined },
    auth: 'RvYGmY1bZqlbMukS8pP9DPEifG6CEBEs:',
    hostname: 'api.segment.io',
    port: null,
    nativeProtocols: {
    'http:': {
      _connectionListener: [Function: connectionListener],
      METHODS: [Array],
      STATUS_CODES: [Object],
      Agent: [Function],
      ClientRequest: [Function: ClientRequest],
      IncomingMessage: [Function: IncomingMessage],
      OutgoingMessage: [Function: OutgoingMessage],
      Server: [Function: Server],
      ServerResponse: [Function: ServerResponse],
      createServer: [Function: createServer],
      validateHeaderName: [Function: __node_internal_],
      validateHeaderValue: [Function: __node_internal_],
      get: [Function: get],
      request: [Function: request],
      maxHeaderSize: [Getter],
      globalAgent: [Getter/Setter]
    },
    'https:': {
      Agent: [Function: Agent],
      globalAgent: [Agent],
      Server: [Function: Server],
      createServer: [Function: createServer],
      get: [Function: get],
      request: [Function: request]
    }
    }
    } +0ms
    optic-debug {
    optic-debug   cwd: 'C:\\Users\\marvin\\development\\project\\em\\eventmanager-api',
    optic-debug   configPath: 'C:\\Users\\marvin\\development\\project\\em\\eventmanager-api\\optic.yml',
    optic-debug   basePath: 'C:\\Users\\marvin\\development\\project\\em\\eventmanager-api\\.optic',
    optic-debug   capturesPath: 'C:\\Users\\marvin\\development\\project\\em\\eventmanager-api\\.optic\\captures',
    optic-debug   gitignorePath: 'C:\\Users\\marvin\\development\\project\\em\\eventmanager-api\\.optic\\.gitignore',
    optic-debug   opticIgnorePath: 'C:\\Users\\marvin\\development\\project\\em\\eventmanager-api\\.optic\\ignore',
    optic-debug   specDirPath: 'C:\\Users\\marvin\\development\\project\\em\\eventmanager-api\\.optic\\api',
    optic-debug   specStorePath: 'C:\\Users\\marvin\\development\\project\\em\\eventmanager-api\\.optic\\api\\specification.json',
    optic-debug   exampleRequestsPath: 'C:\\Users\\marvin\\development\\project\\em\\eventmanager-api\\.optic\\api\\example-requests',
    optic-debug   testingConfigPath: 'C:\\Users\\marvin\\development\\project\\em\\eventmanager-api\\.optic\\testing.json'
    optic-debug } +0ms
    optic-debug { isLocked: false } +6ms
    optic-debug waiting for lock from pid=21976 sentinel file C:\Users\marvin\.optic\optic-daemon-sentinel_7d83af55-0b54-4a62-9ba8-c7d92a0e8284 +10ms
    optic-debug did not see file, polling +57ms
    optic-debug did not see file, polling +62ms
    optic-debug did not see file, polling +61ms
    optic-debug did not see file, polling +62ms
    optic-debug did not see file, polling +62ms
    optic-debug did not see file, polling +62ms
    optic-debug did not see file, polling +62ms
    optic-debug did not see file, polling +62ms
    optic-debug did not see file, polling +62ms
    optic-debug did not see file, polling +62ms
    optic-debug did not see file, polling +62ms
    optic-debug did not see file, polling +62ms
    optic-debug did not see file, polling +62ms
    optic-debug did not see file, polling +62ms
    optic-debug did not see file, polling +62ms
    optic-debug did not see file, polling +62ms
    optic-debug did not see file, polling +62ms
    optic-debug did not see file, polling +63ms
    optic-debug did not see file, polling +62ms
    optic-debug did not see file, polling +62ms
    optic-debug did not see file, polling +62ms
    optic-debug did not see file, polling +62ms
    optic-debug did not see file, polling +62ms
    optic-debug did not see file, polling +62ms
    optic-debug did not see file, polling +62ms
    optic-debug did not see file, polling +62ms
    optic-debug did not see file, polling +62ms
    optic-debug did not see file, polling +62ms
    optic-debug did not see file, polling +62ms
    optic-debug did not see file, polling +62ms
    optic-debug did not see file, polling +62ms
    optic-debug did not see file, polling +62ms
    optic-debug did not see file, polling +62ms
    optic-debug did not see file, polling +62ms
    optic-debug did not see file, polling +62ms
    optic-debug did not see file, polling +62ms
    optic-debug did not see file, polling +62ms
    optic-debug did not see file, polling +62ms
    optic-debug did not see file, polling +62ms
    optic-debug did not see file, polling +62ms
    optic-debug saw file! +62ms
    optic-debug lock created from pid=21976 +1ms
    optic-debug trying to read lockfile contents +0ms
    optic-debug lockfile contents: {"port":34444,"pid":21976} +1ms
    optic-debug api base url: http://localhost:34444/api +0ms
    optic-debug {
    optic-debug   cliSession: {
    optic-debug     session: {
    optic-debug       id: '1',
    optic-debug       path: 'C:\\Users\\marvin\\development\\project\\em\\eventmanager-api'
    optic-debug     }
    optic-debug   }
    optic-debug } +23ms
LouManglass commented 2 years ago

Hi @affeldt28,

Thanks for the report. It looks like we're not opening the browser correctly on the Windows platform. The Optic web service is running, but the CLI command does not cause your browser to open to the appropriate page.

When i use api start i can access the page (http://localhost:34444/apis/1/diffs). I found out that when I strg+c out of api start the webserver isn't closing, so it's still occupying the port. When I now kill the process manually and start api spec, it will start the webserver. It will just not open the browser, neither a console output that it's up and running. And after the command finishes automatically, the webserver is still open.

Aside from the browser not opening, that's intended behavior - Once you start Optic, whether it's with the start, spec, or other commands, it spawns the web server as a daemon process that stays alive to allow you to review your documentation and any diffs detected at any time. You don't need to kill the process spawned by api start to run api spec - Optic should just see the existing daemon, and open the browser.

We're working on making this entire onboarding flow better, which will include resolving the issue of opening the browser appropriately. You can see more information on our beta version, let me know if this looks interesting.

In the meantime, while we're heads down working on delivering these new features, you can load the documentation page manually as needed in Optic 10. I know it's not the same as having the command operate as intended, though the only thing those commands do is assure the Optic daemon/web server is running. The failure to open the page doesn't hide any other limitations, and you're not missing any command line output or other feature.

affeldt28 commented 2 years ago

maybe as proposal a command line output on api spec that the webserver is running would be nice, just like on api start :D

LouManglass commented 2 years ago

@affeldt28 Great point, at least some kind of feedback would be nice!