Skipped jobs count as passed if needed or depended on

Hello,

It seems that needs: and dependencies: directives in .gitlab-ci.yml don't treat skipped jobs properly.

If a job depends on a skipped job, then it will still run. These jobs should also be skipped, or be marked as failures. This is particularly a problem when you have multiple jobs that are dependent on passing output to one another. Unless you depend on all of the prior jobs passing, a failure will only cause the next job to be skipped, but all of the other jobs will try to run, possibly having them bounce back and forth in a pass/fail state.

To reproduce

Create a .gitlab-ci.yml with three jobs:

stages:
  - a
  - b
  - c

x:
  stage: a
  script:
    - exit 1  # Guaranteed failure
y:
  stage: b
  needs: ["x"]
  script:
    - echo "it worked?"  # should pass, if it would be run.
z:
  stage: c
  needs: ["y"]
  script:
    - echo "we tried to stop it..."  # shouldn't be run, but will pass

Maybe I'm confused and it should be running z, and I need to say needs: ["x", "y"], then so be it, but it doesn't seem to make sense to treat a skipped stage as a passed stage.

See https://gitlab.com/KaiSforza/deptest/-/jobs/353360555